如何在不以频道所有者身份登录 google 的情况下使用 Youtube Analytics API 从授权频道接收数据?

How to receive data from authorized channel with Youtube Analytics API without being logged into google as the channel owner?

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

我已经看到我需要 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 分析数据是私人用户数据。私人数据需要用户同意才能访问。只有在用户同意的情况下,您才能访问它。

API 键用于访问 public 数据。喜欢 YouTube 搜索 public 个 youtube 视频。一些 public Google 日历和 public google 驱动器文件。