gpt4 book ai didi

javascript - 如何在不以 channel 所有者身份登录谷歌的情况下使用 Youtube Analytics API 从授权 channel 接收数据?

转载 作者:行者123 更新时间:2023-11-30 19:39:15 26 4
gpt4 key购买 nike

我一直在使用 Youtube Analytics API v2 从 youtube channel 检索信息,当我使用它从当前通过 OAuth2.0 验证的用户的 channel 接收报告时,它一直在为我工作,我使用了示例在他们的网站上编写代码来执行此操作,现在我需要的是接收这些报告,而无需以已向 API 授予所需权限的 channel 所有者身份登录,我该怎么做?

我已经看到我需要 apiKey 才能这样做,我已经在代码中的每个地方尝试了 gapi.client.setApiKey("API_KEY") 代码,但我没有得到任何结果,也许我'我缺少其他东西,我从 youtube 分析网站上选择了示例代码,并将“ids”参数从“channel==MINE”更改为“channel==PREVIOUSLY_AUTHORIZED_CHANNEL_ID”,现在当我尝试时出现错误 403(禁止)无需使用相应的 Google 帐户即可访问它。

<script src="https://apis.google.com/js/api.js"></script>
<script>
function authenticate() {
gapi.client.setApiKey("<API_KEY>");
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/yt-analytics.readonly"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
return gapi.client.load("https://youtubeanalytics.googleapis.com/$discovery/rest?version=v2")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.youtubeAnalytics.reports.query({
"ids": "channel==<PREVIOUSLY_AUTHORIZED_CHANNEL_ID>",
"startDate": "2017-01-01",
"endDate": "2017-12-31",
"metrics": "views,estimatedMinutesWatched,averageViewDuration,averageViewPercentage,subscribersGained",
"dimensions": "day",
"sort": "day"
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: '17857976174-df6g4g2kajnh8mpoebk0o10n4o7ddvb8.apps.googleusercontent.com'});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>

最佳答案

now all I need is to receive these reports without being authenticated as the owner of the channel, how can I do it?

你不能。 YouTube 分析数据是私有(private)用户数据。私有(private)数据需要用户同意才能访问。只有征得用户同意,您才能访问。

API key 用于访问公共(public)数据。喜欢 YouTube 搜索公开的 youtube 视频。一些公共(public)谷歌日历和公共(public)谷歌驱动器文件。

关于javascript - 如何在不以 channel 所有者身份登录谷歌的情况下使用 Youtube Analytics API 从授权 channel 接收数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55584314/

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