YouTube API v3 detects subscription to channel

I want to find out if an authenticated user is subscribed to a specific YouTube channel in the YouTube API 3.

A possible solution would be to get a list of all the signatures of the current authenticated user and check if the channel identifier is in this list. This would be a very inefficient solution and could take a very long time if the user has hundreds of subscribers.

Is there an easy way to check this? I looked through all the API documentation and found nothing.

+4
source share
2 answers

Use the subscriptions # list method and pass mine= true and the identifier of the channel you want to check forChannelId. If the authenticated user is not subscribed to this channel, he will return an empty list.

+9
source
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': ''}
);
0
source

Source: https://habr.com/ru/post/1534894/


All Articles