Google Sign-In gives error when swiching to secondary Youtube accounts

一个人想着一个人 提交于 2020-01-01 08:04:04

问题


I am currently trying to use gapi.auth2 from Google Sign-In for Websites API and this is the code I have:

-- load the library with:

<script src="https://apis.google.com/js/platform.js?onload=onLoadGapiCallback" async defer></script>

-- initialize an auth2 variable:

var auth2;

window.onLoadGapiCallback = () => {
  gapi.load('auth2', () => {
    auth2 = gapi.auth2.init({
      'client_id': 'CLIENT_ID',
      'scope': 'profile email https://www.googleapis.com/auth/youtube.readonly'
    });
  });
};

-- and when a botton is clicked do:

auth2.signIn().then(() => {
  console.log('auth is:', auth2.currentUser.get().getAuthResponse().access_token);
});

This works well, it initializes the auth2 variable, when I click the button, it shows the SingIn prompt and I choose one of my Google Accounts. The problem is from now on when I have to choose a YouTube account, if I choose other account than the main one, I'll get an Exception Object like this one:

{type: "tokenFailed", idpId: "google", error: "USER_LOGGED_OUT"}

also there's an XHR request being sent lastly that has this response:

{"error":"USER_LOGGED_OUT","detail":"No active session found."}

So it only works if I choose the main account, but I cannot choose other YouTube accounts.

What am I missing here? I've looked into all these docs but none helped me:

Getting profile information

Google Sign-In JavaScript client reference

Monitoring the user's session state

Update: Running the code from this example (but with this scope: 'profile email https://www.googleapis.com/auth/youtube.readonly') will only work if I choose the first Youtube account for each Google account. If I choose any other Youtube account, I'll get this alert error:

来源:https://stackoverflow.com/questions/37951665/google-sign-in-gives-error-when-swiching-to-secondary-youtube-accounts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!