dannepanne dannepanne - 1 year ago 93
Javascript Question

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" in the javascript console.

Since I could not identify the error I finally copy/pasted the example code from Google, which can be found here: https://developers.google.com/+/web/people/#retrieve_an_authenticated_users_email_address

The only thing I changed was the Client ID (for web applications).

And I STILL get the same error!

Since the example code does not work for me, I'm thinking, maybe my settings in the Google API Console are wrong. I have tried to follow the instructions:

  • Google+ API Service is active

  • Redirect URIs: none

  • JavaScript origins are set to localhost and the actual production

Have also tried to upload the example code to the production server, just to see if this was a local environment issue, but I still get the same error.

Answer Source

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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download