YouTubeAnalytics.Reports.query : 关联通道的身份验证

YouTubeAnalytics.Reports.query : Authentication to associated channel

我已经设法安排了 google 应用程序脚本文档中可用的示例代码;从我关联的 YouTube 频道检索数据。

function myFunction() {
  var channelId ={MY ASSOCIATED CHANNEL ID};
  // Set the dates for our report
  var today = new Date();
  var oneMonthAgo = new Date();
  oneMonthAgo.setMonth(today.getMonth() - 1);
  var todayFormatted = Utilities.formatDate(today, 'UTC', 'yyyy-MM-dd')
  var oneMonthAgoFormatted = Utilities.formatDate(oneMonthAgo, 'UTC', 'yyyy-MM-dd');
//query
  var analyticsResponse = YouTubeAnalytics.Reports.query(
    'channel==' + channelId,
    oneMonthAgoFormatted,
    todayFormatted,
    'views,likes,dislikes,shares',
    {
      dimensions: 'day',
      sort: '-day'
    });
//output
Logger.log(analyticsResponse)
}

我不确定如何将脚本验证到我关联的频道。

能否请您帮助更正代码。

谢谢,

阿尼什

  1. 转到菜单资源 -> 高级 Google 服务
  2. 开启 Youtube 分析
  3. 转到 Google 开发人员控制台(在 window 底部有 link)或单击此处:https://console.developers.google.com/apis/library
  4. 点击 YouTube 分析工具 API
  5. 点击启用

PS:确保您使用的脚本属于与该频道关联的 gmail 帐户。