简体   繁体   中英

How we should create the credential to connect to google analytics via Python?

I used the google Python example to connect to google analytics and collect all data. I was able to connect and collect data when I use this example, but when I change the profile_id to select a different view, I got the following error:

was:

profile_id = get_first_profile_id(service)

now:

profile_id = '68444917

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A168847831&start-date=2018-01-01&end-date=2019-02-01&metrics=ga%3Asessions%2Cga%3AtotalEvents%2Cga%3Ausers&dimensions=ga%3AeventAction%2Cga%3Adate%2Cga%3AcontentGroup2%2Cga%3AcontentGroup3&filters=ga%3AeventAction%3D%3DDealer+site&samplingLevel=HIGHER_PRECISION&include-empty-rows=true&start-index=1&max-results=10000&alt=json returned "User does not have sufficient permissions for this profile.">

The admin checked my permission based on questions 1 and 2 and it looks I have access to all views.

It is needed the permission granted to the created email account by google analytics as mentioned here :

The newly created service account will have an email address that looks similar to:

quickstart@PROJECT-ID.iam.gserviceaccount.com
Use this email address to add a user to the Google analytics view you want to access via the API. For this tutorial only Read & Analyze permissions are needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM