Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

google analytics - My JSON api key is not in correct format

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"
}

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'],

What I'm doing wrong? I'm using oauth2client that comes with google_api_python_client.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It sounds like you are using ServiceAccountCredentials.from_json() to load your key file.

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.

Try using ServiceAccountCredentials.from_json_keyfile_name() instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...