我创建了一个使用 recently announced Gmail API 的小型应用程序在收到的电子邮件中搜索特定字符串。我的新应用程序在 Chrome/Google Apps 商店中以隐藏形式发布,并且我了解到应该向我提供 OAuth2 凭据以与我的应用程序一起使用。
例如,this guide (for the old apps marketplace, which is no longer usable)显示开发人员可以在哪里获取其市场应用程序的凭据:
但是在新商店中,我找不到任何可以为我提供这些凭据的地方。
我是不是漏掉了一步?我需要填写 Google Apps Marketplace Listing Review Request为了获得凭据?
谢谢!
已更新解决方案
用户 MeLight 的答案如下:生成服务帐户凭据,然后在确保该项目已链接到 Chrome 网上应用店中的市场应用后使用它们。对于 future 的 Google 员工,以下是用于连接到 API 并创建服务
对象的代码,该对象可用于获取消息等。
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.discovery import build
from oauth2client.tools import run
import os
import httplib2
BASEDIR = os.path.dirname(__file__)
PRIVATE_KEY = BASEDIR + "XXXX-privatekey.p12"
SERVICE_ACCOUNT_EMAIL = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2fafafafae2c6c7d4c7cecdd2c7d08cc5d1c7d0d4cbc1c7c3c1c1cdd7ccd68cc1cdcf" rel="noreferrer noopener nofollow">[email protected]</a>"
SCOPES = ["https://mail.google.com/"]
USERNAME="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="71021e1c141e1f1431051003161405040214035f121e1c" rel="noreferrer noopener nofollow">[email protected]</a>"
def main(argv):
f = file(PRIVATE_KEY, 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(service_account_name=SERVICE_ACCOUNT_EMAIL,
private_key=key,
scope=" ".join(SCOPES),
prn=USERNAME)
http = httplib2.Http()
# Authorize the httplib2.Http object with our credentials
http = credentials.authorize(http)
# Build the Gmail service from discovery
service = build('gmail', 'v1', http=http)
最佳答案
您需要转到 Cloud Console,可以在此处找到它:https://console.developers.google.com/
在列表中找到您的项目并单击它。从那里 API 和 AUTH
-> 凭据
。
您应该看到客户端列表及其凭据。您需要一个服务帐户
- 如果尚不存在,您可以创建一个。
关于google-oauth - 为了获取我的市场应用程序的 OAuth2 凭据,需要什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24433630/