5

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

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

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

4

2 回答 2

12

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

于 2014-04-03T20:27:06.683 回答
0
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': ''}
);
于 2017-07-24T12:10:49.040 回答