Got 403 error when connecting to Google Analytics with Python 2.7.x

I tried to get data from Google Analytics API with Python client(google-api-python-client). Here’s the code I used:

from apiclient import discovery
from oauth2client.client import SignedJwtAssertionCredentials
from httplib2 import Http

with open("ManagementGate-622edd43c0dd.p12") as f:
    private_key =

credentials = SignedJwtAssertionCredentials(
    '[email protected]',

http_auth = credentials.authorize(Http())

service ='analytics', 'v3', http=http_auth)

result =

I created a Service Account on Credentials Page. However, I got an error as below:

googleapiclient.errors.HttpError: <HttpError 403 when requesting returned "User does not have any Google Analytics account.">

The instructions I followed are from:
Is there anything else I need to do? And why did I get this error? I already enabled Analytics API on APIs page.

Best answer

You are trying to access the Google Analytics API using a service account. A service account by default does not have access to any Google Analytics accounts.

What you need to do is take the Service account email address from the Google Developer console. Go to the Admin section of the Google Analytics Website. Give this service account access at the ACCOUNT level it must be the ACCOUNT level to the Google Analytics account you wish to access.

It wont work at the Web property or the view level it must be the Account level.