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?
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.
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.
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.
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.
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With