Dread Boy
Dread Boy

Reputation: 722

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.

Upvotes: 0

Views: 1253

Answers (1)

dorian
dorian

Reputation: 6292

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.

Upvotes: 1

Related Questions