.netgoogle-plus

Why does Google+ API not return email address the first time?


When using the Sign In with Google+ API (via .NET) I acquire the access token and then get the user info using:

https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=XXX

This returns plenty of user info but not the user's email address.

If I then re-attempt the login (which uses exactly the same code) then on the second attempt the user info returned contains the "email" field! Any subsequent login attempts will then return the email address as expected.

Please note, the scope used is:

https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email

Anybody know why the email address is not returned in the first instance?

This is a problem because I require the email address on the first attempt in order to create a user account.


Solution

  • This does seem odd, although it could be related to the userinfo methods being deprecated (and scheduled to be removed in September) in favor of using the plus endpoints. Since you're already using the plus.login scope, you can switch to using the plus.people.get endpoint and should change to using the email scope to request the email information.

    See https://developers.google.com/+/api/auth-migration for more about these changes.