Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube API. Check for user was subscribed

What the best way to determine when authorized user was subscribed to YouTube channel by channel's id through YouTube Data API? I assuming it is possible somehow by "Subscriptions.list" API method. But how exactly?

like image 303
drewpts Avatar asked Jan 25 '16 13:01

drewpts


People also ask

How can I get a YouTube channel's subscriptions from the API?

For example, in a subscription resource, the snippet property contains other properties, such as a display title for the subscription. If you set part=snippet, the API response will also contain all of those nested properties. The channelId parameter specifies a YouTube channel ID. The API will only return that channel's subscriptions.

How to get YouTube channel ID?

The snippet.resourceId.channelId property identifies the channel that is being subscribed to. The property value is a unique YouTube channel ID. The channel ID could be obtained in multiple ways, including calling the channels.list method or retrieving search results for channels.

How to retrieve the YouTube subscription feed of authenticated users?

In a subscription resource, the id property specifies the YouTube subscription ID. This parameter can only be used in a properly authorized request. Set this parameter's value to true to retrieve a feed of the authenticated user's subscriptions. This parameter can only be used in a properly authorized request.

What is a subscription resource on YouTube?

A subscription resource contains information about a YouTube user subscription. A subscription notifies a user when new videos are added to a channel or when another user takes one of several actions on YouTube, such as uploading a video, rating a video, or commenting on a video.


Video Answer


1 Answers

If you know the channelId of the channel you want to check the user is subscribed to, you can perform an HTTP GET request on the subscriptions/list endpoint with the parameters part set to id and mine set to true:

HTTP GET https://www.googleapis.com/youtube/v3/subscriptions?part=id&mine=true&key={YOUR_API_KEY}

You could also pass in snippet for part to get information about each channel the user is subscribed to. With this approach, you would have to iterate through every channel that authenticated user is subscribed to, and check if your channel exists in that list.

You could also send an authenticated POST request to the subscriptions/insert endpoint with the channelId of the channel you want to subscribe to with the part param snippet, and if the user is already subscribed to that channel, the request will return a 400 error with the message subscriptionDuplicate.

HTTP POST https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}
like image 186
JAL Avatar answered Oct 04 '22 19:10

JAL