Does the Google JavaScript Client Library support sign-in via Google+ Page?

53 views
Skip to first unread message

Leo Herzog

unread,
Aug 22, 2016, 9:44:11 AM8/22/16
to Google API JavaScript Client
I'm trying to use the Google JavaScript Client API Library to authenticate and interact with the YouTube API on an internal web tool. The person signing in is a Google user who is a manager of several Google+ pages, and those pages are owners of YouTube channels.

I want the user to click my sign-in button on my page, authenticate as their Google+ page, and then my code preforms API calls to that page's YouTube channel.

Right now, I have something like this:
    var clientId = 'my-client-id';
   
var apiKey = 'my-api-key';
   
var scopes = 'profile https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/youtube';

   
var signinButton = document.getElementById('signin');
   
var signoutButton = document.getElementById('signout');

   
function initAuth() {
        gapi
.client.setApiKey(apiKey);
        gapi
.auth2.init({
            client_id
: clientId,
            scope
: scopes
       
}).then(function() {
           
// Listen for sign-in state changes.
            gapi
.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);

           
// Handle the initial sign-in state.
            updateSigninStatus
(gapi.auth2.getAuthInstance().isSignedIn.get());

            signinButton
.addEventListener("click", handleSigninClick);
            signoutButton
.addEventListener("click", handleSignoutClick);
       
});
   
}

   
function updateSigninStatus(isSignedIn) {
       
if (isSignedIn) {
            signinButton
.style.display = 'none';
            signoutButton
.style.display = 'block';
       
} else {
            signinButton
.style.display = 'block';
            signoutButton
.style.display = 'none';
       
}
   
}

   
function handleSigninClick(event) {
        gapi
.auth2.getAuthInstance().signIn();
   
}

   
function handleSignoutClick(event) {
        gapi
.auth2.getAuthInstance().signOut();
   
}

   
// Load the API client and auth library
    gapi
.load('client:auth2', initAuth);

The buttons work perfectly. When my user clicks on the <button id="signin"></button>, it brings up the Google Auth dialog. If they authenticate as themselves, everything works perfectly. However, if they authenticate as a Google+ Page that they own, I get a console error:


TL;DR:


Does anyone know if the Google Javascript Client API library supports authenticating as a Google+ Page, and if so, how I should be handling what is being returned?


Thanks!


Reply all
Reply to author
Forward
0 new messages