Google login error with youtube accounts

I have an application that uses Google Login to get information about a YouTube channel (upload videos, subscriptions, etc.). When a user tries to log in, they can select from the list of Google accounts and after the list of Youtube channels if the user has more than one. But, when the YouTube channel is selected, the API does not work.

var login = function (options) {

  if (!gapi.auth2){
    // Retrieve the singleton for the GoogleAuth library and set up the client.
    gapi.load('auth2', function(){
      gapi.auth2.init({
        client_id: config.credentials.googleApiClientId,
        cookiepolicy: 'single_host_origin',
        scope: 'https://www.googleapis.com/auth/youtube.readonly'
      });
    });
  }

  var GoogleAuth = gapi.auth2.getAuthInstance();
  return GoogleAuth.signIn(options);

};

And in the JavaScript API callback, Google says:

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

+4
source share
1 answer

, , , , , , prompt: 'select_account' signIn fetch_basic_profile: false init :

jsbin, , client_id init , . jsbin.com jsbin .

var auth2 = gapi.auth2.init({
  client_id: '',
  scope: 'https://www.googleapis.com/auth/youtube',
  fetch_basic_profile: false,
  cookie_policy: 'single_host_origin'
});


auth2.signIn({
  scope: 'https://www.googleapis.com/auth/youtube',
  prompt: 'select_account'
}).then(function(result) {
  console.log('Signed in!');
  console.log(result);
}, function(error) {
  console.log(error);
});
0

Source: https://habr.com/ru/post/1622057/


All Articles