17

I'm trying to get Google Analytics data with this guide: https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/

def get_access_token(request): return {'access_t': ServiceAccountCredentials.from_json_keyfile_name( KEY_FILEPATH, SCOPE).get_access_token().access_token } 

With the code above I'm trying to a create a function and return the access token to the context in my admin template.

However. I get this error I don't know what to do with:

('Unexpected credentials type', None, 'Expected', 'service_account') 

What could be the issue here?

1
  • 1
    What value do you have KEY_FILEPATH set to? It sounds like you haven't installed your credentials correctly. Go to the Google developer console and set up a service account and download the credentials. Remember to change the view ID to the view you add the service account to. Commented Aug 2, 2016 at 22:03

2 Answers 2

30

I too was running in to this. The fix in my case was to use the correct json file. I needed to use the one that was saved when I created the service account key, not the one with the service account client:

developer console API key interface

Hope that helps!

Sign up to request clarification or add additional context in comments.

3 Comments

The instructions from the Google Analytics API v4 Quickstart guide are not up to date. Right now this is still the correct answer!
Livesaver. Thank you so much for this fix!
Check out this answer for a step by step guide: stackoverflow.com/a/49965912/2217801
1

It seams like the sample in google-api-python-client has it right

google-api-python-client/tree/master/samples/analytics

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.