我的 JSON api 密钥格式不正确

My JSON api key is not in correct format

我想向 Google Analytics 发出服务器到服务器的请求。我正在使用 Python、webapp2、App Engine。因为我使用 App Engine,所以我已经有服务帐户并且我下载了它的 API 密钥:

{
  "type": "secret",
  "project_id": "secret",
  "private_key_id": "secret",
  "private_key": "secret",
  "client_email": "secret",
  "client_id": "secret",
  "auth_uri": "secret",
  "token_uri": "secret",
  "auth_provider_x509_cert_url": "secret",
  "client_x509_cert_url": "secret"
}

我正在关注 this tutorial,但 get_access_token() 出现错误。在调试库时,我发现代码需要 json 个字段

json_data['_service_account_email'],
scopes=json_data['_scopes'],
private_key_id=json_data['_private_key_id'],
client_id=json_data['client_id'],
user_agent=json_data['_user_agent'],

我做错了什么?我正在使用 google_api_python_client.

附带的 oauth2client

听起来您正在使用 ServiceAccountCredentials.from_json() 加载您的密钥文件。

但是,此构造函数旨在用于序列化的 ServiceAccountCredentials 实例,而不是用于从云控制台下载的密钥文件。

请尝试使用 ServiceAccountCredentials.from_json_keyfile_name()