简体   繁体   中英

Issue fetching data from google analytics api

I've been following Hello Analytics Reporting API v4; PHP quickstart for service accounts in order to complete the set up for an API that will get data from a Google Analytics Report.

I've completed the first three steps as I created the service account, downloaded the private key, and installed the client library. I put the private key JSON file in the same directory as the HelloAnalytics.php sample file I got from the site. I used the view_id that is found in the view settings for the analytics campaign. I then changed the $KEY_FILE_LOCATION to the name of the private key file.

For some reason, when I run sample analytics file, I get the a 403 error saying that permission has been denied even though I have added permission for the API inside of the campaign admin.

Did I skip a step? What could be going wrong?

Yes you have missed a step. Service accounts must be preauthorized.

Add service account to the Google Analytics account

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.

Go to the Google analytics website in the admin section and add the service account email address as a user. At the ACCOUNT level.

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