我的JSON API密钥格式不正确 [英] My JSON api key is not in correct format
问题描述
我想向Google Analytics(分析)发出服务器到服务器的请求.我正在使用Python,webapp2,App Engine.因为我使用App Engine,所以我已经有服务帐户,并且下载了其API密钥:
I want to make server-to-server requests to Google Analytics. I'm using Python, webapp2, App Engine. Because I use App Engine, I already have service account and I downloaded its API key:
{
"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"
}
我正在关注本教程但是get_access_token()
会引发错误.在调试库时,我发现代码需要json字段
I'm following this tutorial but get_access_token()
throws an error. While debugging the library, I discovered the code expects json fields
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.
What I'm doing wrong? I'm using oauth2client that comes with google_api_python_client.
推荐答案
听起来您正在使用ServiceAccountCredentials.from_json()
加载密钥文件.
It sounds like you are using ServiceAccountCredentials.from_json()
to load your key file.
该构造函数应在序列化的ServiceAccountCredentials
实例上使用,而不用于从云控制台下载的密钥文件.
This constructor is meant to be used on a serialized ServiceAccountCredentials
instance, however, and not for a key file as downloaded from the cloud console.
尝试改用ServiceAccountCredentials.from_json_keyfile_name()
.
这篇关于我的JSON API密钥格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!