Created
March 6, 2020 22:40
-
-
Save yoandresaav/27748bb19574977645bc151297e3eb37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If modifying these scopes, delete the file token.pickle. | |
SCOPES = [ | |
'openid', | |
'https://www.googleapis.com/auth/userinfo.email', | |
] | |
def get_user_info(credentials): | |
"""Send a request to the UserInfo API to retrieve the user's information. | |
user_email = get_user_info(credentials)['email'] | |
Args: | |
credentials: oauth2client.client.OAuth2Credentials instance to authorize the | |
request. | |
Returns: | |
User information as a dict. | |
""" | |
user_info_service = build(serviceName='oauth2', version='v2', credentials=credentials) | |
user_info = None | |
try: | |
user_info = user_info_service.userinfo().get().execute() | |
except errors.HttpError, e: | |
logging.error('An error occurred: %s', e) | |
if user_info and user_info.get('id'): | |
return user_info | |
else: | |
raise Exception("El user no tiene correo en su cuenta de google") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment