I have an application that use Google Login for get the information of the YouTube channel (upload videos, subscriptions, etc...). When the user tries to login, they can select from a list of Google accounts and after from a list of Youtube channels if the user have more than one. But, when a YouTube channel is selected, the API fails.
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 callback JavaScript Google API says:
Object {type: "tokenFailed", idpId: "google", error: "USER_LOGGED_OUT"}
Ran into a similar problem, after awhile of experimentation I got this to work, I am not entirely sure what was the problem the things I changed is adding prompt: 'select_account'
to the signIn
call options and fetch_basic_profile: false
to the init
call options:
Here's a jsbin that might work for you, make sure to add your own client_id to the init call and make sure to whitelist output.jsbin.com domain and preview the jsbin from that domain.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With