为我的 google 服务帐户获取授权令牌密钥

Getting authorization token-key for my google service account

我实际上想用这个 api 回复我的 google 播放应用程序的评论: https://developers.google.com/android-publisher/reply-to-reviews#gaining_access 但是在这里,它要我输入auth_token。首先,我将服务帐户添加到我的 google 游戏中。之后,我创建了一个密钥,并为我的密钥下载了 json 文件。使用这个 json 文件我试图获得授权。 token 但此代码的输出告诉我凭据无效且令牌为“none”。我想解决这个问题。谢谢。

from google.oauth2 import service_account
import googleapiclient.discovery

SCOPES = ['https://www.googleapis.com/auth/cloud-platform',
          'https://oauth2.googleapis.com/token',
          'https://accounts.google.com/o/oauth2/auth',
          'https://www.googleapis.com/oauth2/v1/certs',
          'https://www.googleapis.com/robot/v1/metadata/x509/myusername.gserviceaccount.com']
SERVICE_ACCOUNT_FILE = 'service.json'

credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)

print(credentials._token_uri)
print(dir(credentials))
print(credentials.valid)
print(credentials.token)

我研究的资源:

https://developers.google.com/identity/protocols/oauth2#serviceaccount https://developers.google.com/identity/protocols/oauth2/service-account#python_1 https://developers.google.com/android-publisher/reply-to-reviews#gaining_access


注意:人们也像这样发送 API 请求:

service = build('drive', 'v3', credentials=credentials)

例如上面的代码用于发送 api 对 google 驱动器的请求。我怎样才能 api 达到我的目的?例如,我想使用“构建”访问 google 播放 api。

构建方法的关键在于,它首先获取 API,然后获取您要访问的 api 的版本,然后是您的凭据。

service = build('drive', 'v3', credentials=credentials)

如果您检查 Discovery services,您将找到所有 google apis

的列表

android发布者条目如下

 {
      "kind": "discovery#directoryItem",
      "id": "androidpublisher:v3",
      "name": "androidpublisher",
      "version": "v3",
      "title": "Google Play Android Developer API",
      "description": "Lets Android application developers access their Google Play accounts.",
      "discoveryRestUrl": "https://androidpublisher.googleapis.com/$discovery/rest?version=v3",
      "icons": {
        "x16": "https://www.gstatic.com/images/branding/product/1x/googleg_16dp.png",
        "x32": "https://www.gstatic.com/images/branding/product/1x/googleg_32dp.png"
      },
      "documentationLink": "https://developers.google.com/android-publisher",
      "preferred": true
    },

这意味着以下内容应该是您要查找的内容。

service = build('androidpublisher', 'v3', credentials=credentials)