Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name, Email from Google's OAuth API

I want to allow users to login with google on a site and collect their name and email address but I can't find any documentation on the userinfo scope for google's api: https://www.googleapis.com/auth/userinfo.

Thanks

like image 307
Ash Avatar asked Sep 12 '11 20:09

Ash


3 Answers

This is a better way to get the name and email.

Set your scopes to:

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

and

https://www.googleapis.com/auth/userinfo.profile

And use the endpoint:

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

That will get you all you need!

like image 186
Jon Mabe Avatar answered Sep 27 '22 21:09

Jon Mabe


I use http://www-opensocial.googleusercontent.com/api/people/ and https://www.googleapis.com/auth/userinfo#email as the scope of the request tokens.

The protected resource url is https://www-opensocial.googleusercontent.com/api/people/@me/@self to get the current user's data.

I get the user's G+ profile and name. I'm not able yet to get the user's email but I think i'm close

like image 32
alfonso.kim Avatar answered Sep 27 '22 22:09

alfonso.kim


Retrieve OAuth userinfo using the Google Python API:

https://developers.google.com/api-client-library/python/start/installation https://developers.google.com/api-client-library/python/guide/aaa_oauth

import httplib2
from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow

http = httplib2.Http()
http = credentials.authorize(http)

users_service = build('oauth2', 'v2', http=http)
user_document = users_service.userinfo().get().execute()
like image 30
Desmond Lua Avatar answered Sep 27 '22 21:09

Desmond Lua