I am trying to return GA
API response but having a authentication error, which I don't know why. What I have done so far is right below.
<meta name="google-signin-client_id" content="MY_CLIENT_ID">
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/analytics.readonly">
<script src="https://apis.google.com/js/platform.js?onload=init" async defer></script>
<script src="https://apis.google.com/js/client:platform.js"></script>
then gapi
response method.
queryReports() {
gapi.client.request({
path: '/v4/reports:batchGet',
root: 'https://analyticsreporting.googleapis.com/',
method: 'POST',
body: {
reportRequests: [{
viewId: "82708385",
dateRanges: [{
startDate: '7daysAgo',
endDate: 'today'
}],
metrics: [{
expression: 'ga:sessions'
}]
}]
}
})
.then(res => {
console.log(res.result)
})
.catch(err => {
console.log(err)
})
},
But in the end it's catching an AUTH error. The thing is. I already create a OAuth 2.0 Client ID
credentials in console.developers.google.com/apis/credentials?
and using that client_id
in meta.
error is:
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.
It's look like I am missing something here? How can I solve this issue.