Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

('Unexpected credentials type', None, 'Expected', 'service_account') with oauth2client (Python)

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?

like image 420
Urdro Avatar asked Aug 01 '16 22:08

Urdro


2 Answers

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!

like image 116
Charles Brandt Avatar answered Nov 02 '22 23:11

Charles Brandt


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

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

like image 25
mdob Avatar answered Nov 03 '22 01:11

mdob