gpt4 book ai didi

javascript - 获取谷歌分析API响应

转载 作者:行者123 更新时间:2023-11-28 03:10:44 25 4
gpt4 key购买 nike

我正在尝试返回 GA API 响应,但出现身份验证错误,我不知道为什么。到目前为止我所做的就在下面。

<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>

然后是gapi响应方法。

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)
})
},

但最终它捕获了AUTH错误。事情是。我已在 console.developers.google.com/apis/credentials? 中创建了 OAuth 2.0 客户端 ID 凭据,并在元中使用该 client_id

错误是:

"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.

我好像漏掉了什么?我该如何解决这个问题。

最佳答案

Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.

您似乎已经设置了您的客户端 ID。下一个要考虑的错误逻辑是您的凭据有问题。要么您错误地复制了客户端 ID,要么您创建了错误的类型。

我认为这是您的客户端的设置问题。如果你查看教程Hello analytics reporting java script.

enter image description here

如您所见,您需要创建类型 Web 应用程序。根据您的评论,您创建的其他类型将无法工作,因为它用于已安装的应用程序。

关于javascript - 获取谷歌分析API响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60145224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com