【发布时间】:2014-09-12 09:20:38
【问题描述】:
我正在尝试构建一个 Gmail 服务,该服务将在用户的 IT 管理员在应用市场上对应用进行身份验证后读取用户的电子邮件。从文档来看,服务帐户似乎是合适的选择,我尝试了这两种方法:
scope = "https://www.googleapis.com/auth/gmail.readonly"
project_number = "c****io"
authorization_token, _ = app_identity.get_access_token(scope)
logging.info("Using token %s to represent identity %s",
authorization_token, app_identity.get_service_account_name())
#authorization_token = "OAuth code pasted from playground"
response = urlfetch.fetch(
"https://www.googleapis.com/gmail/v1/users/me/messages",
method=urlfetch.GET,
headers = {"Content-Type": "application/json",
"Authorization": "OAuth " + authorization_token})
和
credentials = AppAssertionCredentials(scope=scope)
http = credentials.authorize(httplib2.Http(memcache))
service = build(serviceName='gmail', version='v1', http=http)
listReply = gmail_service.users().messages().list(userId='me', q = '').execute()
然后我按照Unable to access BigQuery from local App Engine development server 启动了 dev_appserver.py
但是,我收到 HTTP 错误代码 500“后端错误”。相同的代码,但是当我从 OAuth 游乐场粘贴 access_token 时,它工作正常(HTTP 200)。我在我的本地机器上,以防万一。想知道我是否遗漏了什么?我正在尝试查找其 IT 管理员安装了我的 Google Marketplace 应用程序的特定域的所有用户的所有电子邮件。
感谢您的帮助!
【问题讨论】:
标签: google-app-engine google-oauth google-api-python-client gmail-api