Skip to content Skip to sidebar Skip to footer

Getting "gapi.client Is Undefined" When Trying To Retrieve An Authenticated Google+ User's Email Address

I'm trying to retrieve user data from a visitor who has signed in to my site using google + sign in button, but I just end up with the message 'TypeError: gapi.client is undefined'

Solution 1:

You must include the script and include the client API in addition to the plusone script:

<scriptsrc="https://apis.google.com/js/client:plusone.js"type="application/javascript"></script>

The demo page was doing it incorrectly, which I've fixed.

Solution 2:

gapi.client.load('plus', 'v1', function() {

    var request = gapi.client.plus.people.get({
        'userId': 'me'
    });

    request.execute(function(response) {
        console.log(response);   
    });
});

Solution 3:

This may sound stupid.. but sometimes you just need to close and reopen the browser...

I tried almost all solutions among almost all relevant SO questions, nothing worked.

Finally I decided to see if it was working with another browser, and it did... hence I just closed and reopened the browser I was working in.. and voilà.

I am not sure why it was not working. I was not caching requests, I was reloading the page each time with ctrl-F5 and had also disabled caching within dev tools (for when dev tools are in use).

Solution 4:

Here are two of the reasons I've gotten his error and I'll update in the future if/when I encounter any more.

  1. One of the errors I encountered was that the variables were not being loaded. I use Waterfox by default though I felt like I wasn't getting any useful information. I used Chrome and it gave me a useful error message about the authorize button being null. I had to move the authorizeButton (which I made proper by removing camelCase) directly in to the functions and everything worked.

  2. I also disable third party cookies by default and again I wasn't getting any useful information. I literally slowly recreated the Waterfox profile until I got to the preferences file and eventually determined that the preference was for third party cookies, enabled them and it all worked again.

Post a Comment for "Getting "gapi.client Is Undefined" When Trying To Retrieve An Authenticated Google+ User's Email Address"