为什么我不能通过我的Youtube品牌帐户(使用Google JS API客户端)进行身份验证?

问题描述 投票:0回答:1

我正在使用Google API JS客户端连接到我的YouTube帐户,以收集我的视频的Analytics(分析)。问题是其中一些是在我拥有的品牌帐户上,尝试连接到我的品牌帐户时,我总是收到错误消息。

Console Error when I select brand account from the accounts pop window

这里是video showing the problem

是否有其他方法可以访问我拥有的品牌帐户的分析数据?我应该注意,我不是YouTube或类似内容的内容合作伙伴。

JS Code (from developers.google.com)

<script src="https://apis.google.com/js/api.js"></script>
<script>
function authenticate() {
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==MINE",
  "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: 'YOUR_CLIENT_ID'});
 });
</script>
 <button onclick="authenticate().then(loadClient)">authorize and load</button>
 <button onclick="execute()">execute</button>
javascript youtube-api gapi youtube-analytics-api
1个回答
0
投票

您知道吗?我遇到了同样的问题。适用于我的Gmail youtube帐户,但不能使用我有权访问的youtube品牌帐户。

© www.soinside.com 2019 - 2024. All rights reserved.