扩展 jonathanberi 的评论,
在这个答案中,谷歌已经弃用了 Oauth1 和 OpenId。Google 建议对所有市场应用程序使用 OAuth2,尤其是在新体验发布之后
这是一些示例代码
def get(self, *args, **kwargs):
code = self.get_argument('code', None)
error = self.get_argument('error',None)
redirect_uri = "{protocol}://{host}{path}".format( protocol = self.request.protocol,
host = self.request.host,
path = self.request.path)
flow = OAuth2WebServerFlow(
client_id = config['CLIENT_ID'],
client_secret= config['CLIENT_SECRET'],
scope = 'https://www.googleapis.com/auth/userinfo.email',
redirect_uri = redirect_uri,
access_type = 'online'
)
if code is None:
auth_uri = flow.step1_get_authorize_url()
self.redirect(auth_uri)
elif error:
self.redirect("http://error.com")
else:
credentials = flow.step2_exchange(code)
http = httplib2.Http()
http = credentials.authorize(http)
service = build('oauth2', 'v2', http=http)
user = service.userinfo().get().execute()