【问题标题】:YouTube Analytics with Google Apps Script for a Brand AccountYouTube Analytics with Google Apps Script for a Brand Account
【发布时间】:2023-01-27 04:09:37
【问题描述】:

您好,我正在尝试获取品牌帐户的 YouTube 分析。我正在使用 Google Apps 脚本,但现在我遇到的问题是我总是获取 Google 帐户而非品牌帐户的信息。目前我正在使用这段代码。

function retrieveMyUploads() {

  var results = YouTube.Channels.list('contentDetails', {mine: true});
  for(var i in results.items) {
    var item = results.items[i];
    // Get the playlist ID, which is nested in contentDetails, as described in the
    // Channel resource: https://developers.google.com/youtube/v3/docs/channels
    var playlistId = item.contentDetails.relatedPlaylists.uploads;

    var nextPageToken = '';

    // This loop retrieves a set of playlist items and checks the nextPageToken in the
    // response to determine whether the list contains additional items. It repeats that process
    // until it has retrieved all of the items in the list.
    while (nextPageToken != null) {
      var playlistResponse = YouTube.PlaylistItems.list('snippet', {
        playlistId: playlistId,
        maxResults: 25,
        pageToken: nextPageToken
      });

      for (var j = 0; j < playlistResponse.items.length; j++) {
        var playlistItem = playlistResponse.items[j];
        Logger.log('[%s] Title: %s',
                   playlistItem.snippet.resourceId.videoId,
                   playlistItem.snippet.title);

      }
      nextPageToken = playlistResponse.nextPageToken;
    }
  }

} 

如果有人可以帮助我获取品牌帐户而不是 Google 帐户的信息,那就太好了。

【问题讨论】:

    标签: google-apps-script youtube-data-api youtube-analytics-api


    【解决方案1】:

    我不知道 YouTube 建议如何获取授权令牌,但这是我将其用于品牌帐户的方式:

    https://developers.google.com/youtube/v3/docs/channels/list 上登录关联的 Google 帐户,然后在右侧窗格中,将 snippet 填写为 part,将 true 填写为 mine,打开网络浏览器的网络选项卡(控制键+转移+),单击右窗格底部的执行,然后选择您连接的帐户,然后选择品牌帐户,并从网络选项卡的 XHR 请求中获取为授权标头提供的 AUTHORIZATION_TOKEN

    然后你可以运行这个 shell 命令来确保你得到正确的 AUTHORIZATION_TOKEN 来满足你的需要。

    curl 'https://youtube.googleapis.com/youtube/v3/channels?part=snippet&mine=true' --header 'Authorization: Bearer AUTHORIZATION_TOKEN'
    

    在响应中,您应该会看到品牌帐户的名称,这样您就可以修改端点以满足您的需求。

    【讨论】:

    • 令牌有效期多长?
    • 不知道,但我认为使用网络选项卡了解 YouTube 数据 API v3 网站如何生成此令牌,如果它过期,您可以自动重新生成它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多