2
votes

I'm trying to access the Google Analytics API via Google Sheets (Google Script).

So within the script, I'm trying to use the URI as described here: https://developers.google.com/analytics/devguides/reporting/realtime/v3/reference/data/realtime/get

The API call looks something like this:

GET https://www.googleapis.com/analytics/v3/data/realtime?ids=3254435&metrics=ga%3AActiveUsers&key={YOUR_API_KEY}

Within my Google Analytics Script, I've also created a Public API Access key: enter image description here

However, I can't seem to get any data whether if I'm appending the token key in the URI or within the header.

Can any one point me to the right direction?

Thanks

2

2 Answers

2
votes

The public api key is for public access APIs. Data that is not owned by a user. You need to create client id from web application.

Then you will be able to authenticate it using Oauth2.

this might get you started. https://developers.google.com/apps-script/advanced/analytics

How to know when you need to be authenticated:

Requires authorization

If the documentation says requires authentication then you have to be authenticated to access that call.

0
votes

You can use Google Analytics API easily just by enabling them in App Script.

Below is the Guide to using Real-time API in Google Spreadsheet https://www.tatvic.com/blog/google-analytics-real-time-data-in-google-sheet/

Just like above you can use any API no need to take care of tokens.