【问题标题】:How to get the subscriber count of a YouTube channel to Google Sheets如何获取 YouTube 频道的订阅者数量到 Google 表格
【发布时间】:2021-06-05 21:31:24
【问题描述】:

我有一份 YouTube 频道的网址列表。如何将他们的订阅者数量添加到 Google 表格中?

【问题讨论】:

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


    【解决方案1】:

    需要 YouTube 数据 API v3 凭据。见:

    获得 API 密钥后:

    1. 将您的 URL 列表添加到 Google 表格中。

    2. 创建一个新的 Google Apps 脚本项目。 (工具 > 脚本编辑器)

    3. 将此代码粘贴到您的脚本文件中:

       var api_key='YOUR_API_KEY'
       var google_url = 'https://www.googleapis.com/youtube/v3/channels/' 
       var url_id = google_url + '?key=' + api_key + '&part=statistics' + '&id='
      
       function GET_SUBS(input) {
           /** Takes channel ID as input and returns the subscriber count */
           url_id = url_id + input
           return +ImportJSON(url_id, "/items/statistics/subscriberCount", "noHeaders")
       }
      
    4. 单击“文件”旁边的加号图标并选择“脚本”。将新脚本文件重命名为“ImportJSON”和paste this code

    5. 返回工作表并为频道 ID 设置一列。您可以使用以下代码从 URL 中去除频道的 ID:

      =ArrayFormula(REGEXREPLACE('CHANNEL_URL',"(.*\/)(.*)$","$2"))
      

    1. 使用 GET_SUBS() 函数获取关注者数量。

      GET_SUBS('CHANNEL_ID')
      

    注意:目前 YouTube API 并未公开提供频道的确切订阅人数。 See this Stackoverflow question. 所以我们得到的结果是四舍五入的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      • 1970-01-01
      • 2015-08-16
      • 2015-03-27
      • 2021-02-19
      • 1970-01-01
      • 2018-04-21
      相关资源
      最近更新 更多