如何从Google Python SDK oauth2获取电子邮件?

如何从Google Python SDK oauth2获取电子邮件?,python,oauth-2.0,google-calendar-api,Python,Oauth 2.0,Google Calendar Api,这似乎是一个愚蠢的问题,但我确实在谷歌sdk文档中找不到它 如何获取电子邮件地址(xxxxx@gmail.com)从刚刚授权我离线访问其中一个Google API的用户帐户 import httplib2 import datetime from apiclient import discovery from oauth2client import client json_credentials_as_string = "..." credentials = client.OAuth

这似乎是一个愚蠢的问题,但我确实在谷歌sdk文档中找不到它

如何获取电子邮件地址(
xxxxx@gmail.com
)从刚刚授权我离线访问其中一个Google API的用户帐户

import httplib2
import datetime  

from apiclient import discovery
from oauth2client import client


json_credentials_as_string = "..."

credentials = client.OAuth2Credentials.from_json(json_credentials_as_string)
http_auth = credentials.authorize(httplib2.Http())
service = discovery.build('calendar', 'v3', http=http_auth)

# ...?
服务列表中没有提及任何实际获取用户信息的内容


(使用“主要”calendarId),这可能是他们的帐户电子邮件,但我不确定它是否必须是?如果有人更改了他们的主日历,看起来可能不会返回他们的google电子邮件id(xxxx@gmail.com),这就是我想要的。

在OAuth 2.0范围列表中包含
电子邮件。然后尝试:

print 'Authenticated as: %s' % credentials.id_token[u'email']

在您的OAuth 2.0范围列表中包括
电子邮件
。然后尝试:

print 'Authenticated as: %s' % credentials.id_token[u'email']

什么是作用域url?不要使用url,只使用文字字符串“email”。它在文档中的什么位置?它的作用域url是什么?不要使用url,只使用文字字符串“email”。它在文档中的什么位置?