【问题标题】:YouTube API v3 detect if subscribed to a channelYouTube API v3 检测是否订阅了频道
【发布时间】:2014-05-15 18:04:40
【问题描述】:

我希望能够检测当前经过身份验证的用户是否订阅了 YouTube API v3 中的特定 YouTube 频道。

一种可能的解决方案是检索当前经过身份验证的用户的所有订阅的列表,并检查频道的频道 ID 是否包含在该列表中。如果用户有数百个订阅,那将是一个非常低效的解决方案,并且可能需要很长时间。

有什么简单的方法可以检查吗?我浏览了整个 API 文档,但找不到任何东西。

【问题讨论】:

    标签: youtube youtube-api subscription youtube-channels


    【解决方案1】:

    使用subscriptions#list 方法并传递mine = true 和您要签入forChannelId 的频道ID。如果经过身份验证的用户没有订阅该频道,它将返回一个空列表。

    【讨论】:

    【解决方案2】:
    checkSubscribe (params) {
      var request = 
    gapi.client.youtube.subscriptions.list(removeEmptyParams(params));
      request.execute((response) => {
      console.log(response);
       if (response.code !== 401 && response.code !== 400 && response.items[0] ) {
          console.log('response');
          console.log(response);
         }
        });
     }
      removeEmptyParams(params)[![enter image description here][1]][1]{
        for (const pra in params) {
          if (!params[pra] || params[pra] === 'undefined') {
            delete params[pra];
         }
       }
        return params;
      }
    
    checkSubscribe(
        {part: 'snippet, contentDetails', mine: true},
        {'forChannelId':'PUT-YOUR-CHANEL--ID','onBehalfOfContentOwner': ''}
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-29
      • 1970-01-01
      • 2016-09-16
      • 2015-08-16
      • 2013-06-15
      • 2013-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多