我正在尝试构建一个 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()
然后我根据无法从本地 App Engine 开发服务器访问 BigQuery启动 dev_appserver.py
但是,我收到 HTTP 错误代码 500“后端错误”。相同的代码,但是当我从 OAuth 游乐场粘贴 access_token 时,它工作正常(HTTP 200)。我在我的本地机器上,以防万一。想知道我是否遗漏了什么?我正在尝试查找其 IT 管理员安装了我的 Google Marketplace 应用程序的特定域的所有用户的所有电子邮件。
谢谢您的帮助!