๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Python/Basic

[Oauth] Google, email ์ •๋ณด ์–ป๊ธฐ

๋ฐ˜์‘ํ˜•

serviceName='oauth2', version='v2'

์„œ๋น„์Šค๋ช…, ๋ฒ„์ „ ๋ญ˜๋กœ ํ•ด์•ผํ• ์ง€ ๋ชฐ๋ผ์„œ email ์ •๋ณด ์–ป๊ธฐ ํ•œ์ฐธ ํ—ค๋งด ใ…  ใ… 

์„œ๋น„์Šค๋ช… ์ •๋ณด ์žˆ๋Š” ๊ณณ ์•„์‹œ๋Š” ๋ถ„ ์•Œ๋ ค์ฃผ์„ธ์šง!

import googleapiclient.discovery
def get_user_info(credentials):
	"""Send a request to the UserInfo API to retrieve the user's information.

	Args:
		credentials: oauth2client.client.OAuth2Credentials instance to authorize the
					request.
	Returns:
		User information as a dict.
	"""
	user_info_service = googleapiclient.discovery.build('oauth2', 'v2', credentials=credentials)
	return user_info_service.userinfo().get().execute()
	# 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 NoUserIdException()

user_email = get_user_info(credentials)['email']

 

stackoverflow.com/questions/19473250/how-to-get-user-email-after-oauth-with-google-api-python-client

 

How to get user email after OAUTH with Google API Python Client

I'm currently building a web app interacting with Google API in Python. Using the oauth to get access to the users resources. After successful authentication and upgrade of the token like this:

stackoverflow.com

 

๋ฐ˜์‘ํ˜•