Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Google Analytics API

Hi Google Team,

I am able to execute the below Google Analytics API in the Google Analytics-->Reporting--> Reporting APIv4

curl --request POST \
'https://analyticsreporting.googleapis.com/v4/reports:batchGet?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"reportRequests":[{"viewId":"134778649","dateRanges":[{"endDate":"2023-11-30","startDate":"2010-11-01"}],"metrics":[{"expression":"ga:pageviews"}],"dimensions":[{"name":"ga:userAgeBracket"}]}]}' \
--compressed

But I am not able to get the same response from postman, I get the below error:

"message""Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
I have given the credentials in OAuth 2.0, I am not sure what I am missing. Please let me know if there is specific way to get this working from outside Google.

 

 

 

1 2 2,081
2 REPLIES 2

I would suggest ensuring that your OAuth 2.0 credentials have the necessary scope permissions to access the Google Analytics API. It's possible that your credentials are missing the required scope for this specific API.

To resolve this, here are a few steps you can take:
Double-Check Credentials: Make sure that you've correctly configured the OAuth 2.0 credentials in Postman. Ensure that you have the correct client ID, client secret, and have set up the appropriate OAuth 2.0 flow.
Token Expiry: OAuth 2.0 access tokens have an expiration time. Check if your access token is still valid. If it has expired, you'll need to obtain a new one by going through the OAuth 2.0 authentication process again.
It you seek information or resources related to Google Analytics or API integrations, check out DataHive360. They might provide valuable guides or articles to assist you in setting up your API requests successfully.