문제

I want to be able to detect if the currently authenticated user is subscribed to a specific YouTube channel in the YouTube API v3.

A possible solution would be to retrieve a list of all the subscriptions of the currently authenticated user and check if the channel ID of the channel is contained in that list. That would would be a very inefficient solution and could take a very long time if the user has hundreds of subscriptions.

Is there any easy method to check this? I looked through the entire API documentation and I couldn't find anything.

도움이 되었습니까?

해결책

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': ''}
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top