Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user_info api in the documentation #1071

Closed
nishantwrp opened this issue Oct 20, 2020 · 2 comments
Closed

Add user_info api in the documentation #1071

nishantwrp opened this issue Oct 20, 2020 · 2 comments
Assignees

Comments

@nishantwrp
Copy link

@nishantwrp nishantwrp commented Oct 20, 2020

I was able to retrieve user profile of the user using their credentials i.e. accessToken by the following code

from googleapiclient.discovery import build

def get_user_email_from_credentials(credentials):
    user_info_service = build('oauth2', 'v2', credentials=credentials)
    user_info = user_info_service.userinfo().get().execute()
    return user_info['email']

But I couldn't find it in the docs here https://github.com/googleapis/google-api-python-client/blob/master/docs/dyn/index.md

@parthea
Copy link
Contributor

@parthea parthea commented Nov 12, 2020

Thanks for suggesting an update to the docs! I've opened PR to add the code you suggested. Please review #1088 if you have a chance.

Additionally, I've opened a thread internally to see if we can include a link to the oauth2 docs in our API Library Reference Documentation.

The People V1 api also has a people.get() method which has information about the authenticated user. See the python docs here. The following sample code also provides the authenticated user's email address but your sample is more intuitive :).

people_service = build('people', 'v1', credentials=credentials)
result = people_service.people().get(resourceName='people/me', personFields='emailAddresses').execute()
result.get('emailAddresses')[0].get('value')

@nishantwrp
Copy link
Author

@nishantwrp nishantwrp commented Nov 12, 2020

Hi @parthea,

#1088 looks good to me. Yup it would be nice to have this documented here.

The People V1 api also has a people.get() method which has information about the authenticated user. See the python docs here. The following sample code also provides the authenticated user's email address but your sample is more intuitive :).

This might work but this doesn't seem to be a good idea because I would need to request additional people access from the user, right?

gcf-merge-on-green bot pushed a commit that referenced this issue Nov 13, 2020
…thenticated user (#1088)

Fixes #1071  🦕

Note: I changed `scopes=['profile', 'email'],` to `scopes=['openid', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'],` in the examples because I received a warning that the scope has changed.

> `Warning: Scope has changed from "email profile" to "https://www.googleapis.com/auth/userinfo.email openid https://www.googleapis.com/auth/userinfo.profile".`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants