YouTube API v3 detect if subscribed to a channel

﹥>﹥吖頭↗ 提交于 2019-12-05 09:40:45

Use the subscriptions#list method and pass mine = true and the channel ID you want to check in forChannelId. If the authenticated user is not subscribed to that channel, it will return an empty list.

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': ''}
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!