Youtube api get subbed channels - youtube

is there something in the youtube api to get all channels where I do have a subscription? In general it means to return a list with the channels you can find under youtube.com/feed/channels.
I've looked in the api, but couldn't find. Seems there are only functions to return channels which subbed me, but I need the other way.
Thanks.

I think that you should check activtes.list the response contains subscriptions
activities.resource
},
"subscription": {
"resourceId": {
"kind": string,
"channelId": string,
}
},
This may not be exactly what you are looking for but i think its as close as you will get. I know of no other method that shows what subscriptions a user has.

Related

how do I get youtube shorts from youtube api data v3

I want a way to get YouTube shorts for a specific channel from YouTube API. I looked every where and I couldn't find anything.
Currently I can get a playlist ID for all channel videos with this endpoint:
request = youtube.channels().list(
part="contentDetails",
id=id
)
I also tried these parameters:
request = youtube.channels().list(
part="snippet,contentDetails,statistics,brandingSettings",
id=id
)
So is there a way to get YouTube shorts from a specific channel from YouTube API or any other source if it's available.
One way of detecting if a YouTube video ID is a Short without even using the API is to try a HEAD HTTP request to the /shorts/ version of the URL and see if it redirects you.
https://www.youtube.com/shorts/hKwrn5-7FjQ is a Short and if you visit that URL, you'll get an HTTP status code of 200 and the URL won't change.
https://www.youtube.com/watch?v=B-s71n0dHUk is not a Short, and if you visit https://www.youtube.com/shorts/B-s71n0dHUk, you get a 303 redirect back to the original URL.
Keep in mind, that this behavior might change down the line, but it works as of May 2022.
It seems that once again YouTube Data API v3 doesn't provide a basic feature.
For checking if a given video is a short:
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/videos?part=short&id=VIDEO_ID containing item["short"]["available"] boolean, your problem is solved.
Example of short id: ydPkyvWtmg4
For listing shorts of a channel:
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/channels?part=shorts&id=CHANNEL_ID. The entry item["shorts"] contains the data you are looking for. Note that the pagination works as the one of YouTube Data API v3.
Example of result for channel UC5O114-PQNYkurlTg6hekZw:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC5O114-PQNYkurlTg6hekZw",
"shorts": [
{
"videoId": "fP8nKVauFwc",
"title": "India: United Nations Counter Terrorism Committee Watch LIVE #shorts",
"thumbnails": [
{
"url": "https:\/\/i.ytimg.com\/vi\/fP8nKVauFwc\/hq720_2.jpg?sqp=-oaymwEYCNAFENAFSFryq4qpAwoIARUAAIhC0AEB&rs=AOn4CLCgJEYgv_msT5pkfWeEEN3VBt4wjg",
"width": 720,
"height": 720
}
],
"viewCount": 3700
},
...
],
"nextPageToken": "4qmFsgLlARIYVUM1TzExNC1QUU5Za3VybFRnNmhla1p3GsgBOGdhU0FScVBBVktNQVFxSEFRcGZRME00VVVGU2IyWnZaMWxqUTJob1ZsRjZWbEJOVkVVd1RGWkNVbFJzYkhKa1dFcHpWa2RqTW1GSFZuSlhibU5SUVZOSlVrTm5PSGhQYWtVeVRtcGplVTE2VlRST2FrVXdUbXBCY1VSUmIweFhWRUl5VGtab1dGSllSbGRNVmtVU0pEWXpOakJoTkRVNUxUQXdNREF0TWpKaE15MDRObUV6TFdRMFpqVTBOMlZqWVRSbFl4Z0I=,CgtuNjFmZlJlR0QxcyiVgICbBg=="
}
]
}
Below is a sample python code to send the HEAD HTTP request.
import requests
def is_short(vid):
url = 'https://www.youtube.com/shorts/' + vid
ret = requests.head(url)
if ret.status_code == 200:
return True
else: # whether 303 or other values, it's not short
return False
I don't know why but I don't get status code 303 whether it's a short or not with axios. So this is another way of checking if it's a short or not.
const isShort = async (videoId) => {
const url = "https://www.youtube.com/shorts/" + videoId
const res = await axios.head(url)
console.log(res.request.res.responseUrl)
// if it's a short it ends with "/shorts/videoId"
// if it's NOT a short it ends "/watch?=videoId"
}
Maybe axios automatically redirects?
You can use the new dimension called 'creatorContentType' from Youtube Analytics and Reports API.
// You can get IDs from PlaylistItems or Search API
const IDs = ["videoID1", "videoID2", "videoID3"];
// Get the analytics data of selected videos based on their IDs
const { data: analyticsData } = await youtubeAnalytics.reports.query({
ids: "channel==MINE",
startDate: "2019-01-01",
// Today's date
endDate: new Date().toISOString().split("T")[0],
metrics: "views",
dimensions: "video,creatorContentType",
filters: `video==${IDs.join(",")}`,
access_token,
});
It basically returns values listed below:
Value
Description
LIVE_STREAM
The viewed content was a YouTube live stream.
SHORTS
The viewed content was a YouTube Short.
STORY
The viewed content was a YouTube Story.
VIDEO_ON_DEMAND
The viewed content was a YouTube video that does not fall under one of the other dimension values.
UNSPECIFIED
The content type of the viewed content is unknown.
Notes:
Don't forget it returns values just for the videos uploaded after 01.01.2019.
Don't forget to add analytics scopes and enable Analytics and Reports API.

YouTube API: detect that the video is age-restricted

As per docs:
contentDetails.contentRating.ytRating
A rating that YouTube uses to identify age-restricted content.
But that doesn't seem to work as documented, here's the example: https://www.youtube.com/watch?v=IUc0wyae-WI
API response:
{
"items": [
{
"id": "U9x_WdDwATA",
"contentDetails": {
"contentRating": {},
},
}
]
}
Notice that contentRating.ytRating isn't set which means that the video doesn't have age-restriction according to API.
But actually it's not the case: https://www.youtube.com/embed/IUc0wyae-WI?hl=en
This video is age-restricted and only available on YouTube. Learn more
Watch on YouTube
Where's my mistake? Or is it the bug in YouTube API v3?
try to find playabilityStatus:
see for more details:
Use the YouTube API to check if a video is embeddable
This is undocumented API existing for long time, so exploring it is up
to developer. I am aware of "status" (ok/fail), "errorcode" (100 and
150 in my practice), "reason" (string description of error). I am
getting duration ("length_seconds") this way because oEmbed does not
provide this information (strange, but true) and I can hardly motivate
every employer to get keys from youTube to use official API

What is the maximum size/length of IDs, especially for comment IDs

I'm trying to find the maximum size of the different IDs of the YouTube API.
Can someone tell me where can I found this or what is the maximum number of characters of:
- Comments IDs
- Channels IDs
- Playlists IDs
- Subscriptions IDs
Thank you!
Dan
You can get the Comments ID from the JSON response in the Resource representation ("id": string) section of the documentation.
See the JSON structure of a comments resource
{
"kind": "youtube#comment",
"etag": etag,
"id": string,
"snippet": {
"authorDisplayName": string,
"authorProfileImageUrl": string,
"authorChannelUrl": string,
"authorChannelId": {
"value": string
},
"channelId": string,
"videoId": string,
"textDisplay": string,
"textOriginal": string,
"parentId": string,
"canRate": boolean,
"viewerRating": string,
"likeCount": unsigned integer,
"moderationStatus": string,
"publishedAt": datetime,
"updatedAt": datetime
}
}
Same with Channels ID, Playlist ID, Subscription ID.
Unfortunately, coming from the YouTube developer that they do not guarantee about the length of each specific ID.
Here is a StackExchange post as a reference.
It was mentioned that the word is coming from a YouTube developer, here is the link from Google Groups Forum to justify.
Hello Hans,
I don't see anywhere in the documentation where we officially commit
to a standard length of 11 characters for YouTube video ids. It's one
of those things where we have a current implementation, and it may
stay that way indefinitely. But we're not offering any official
commitment to that, so proceed at your own risk.
A better approach, though one that's more involved, would be to take
each video id and make a request to the YouTube API to see if it's
valid. E.g., make an HTTP GET to
http://gdata.youtube.com/feeds/api/videos/VIDEO_ID
and see if you get back a HTTP 200 response. Of course, if you take
that approach, videos that have been removed from YouTube will come
back as invalid (which may or may not be what you want) and videos
that have been very recently uploaded to YouTube might also come back
as invalid.
Cheers,
-Jeff Posnick, YouTube API Team

No replies or not all comments retrieved using Google YouTube V3 API

I am trying to retrieve all comments to a video with all replies, however, using the Test It interface (or the Java library) I have not been able to retrieve all comments - I have following two examples, when I have failed:
Example 1
The example video and comment is https://www.youtube.com/watch?v=xCLy2DZdXhY&lc=z12ei1s5gs2mc303523qsdigcxmphhlrd04
When I retrieve the comment using
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&id=z12ei1s5gs2mc303523qsdigcxmphhlrd04&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
I receive:
And note the "totalReplyCount": 2, line.
However, when I try to obtain all replies using the parentId:
GET https://www.googleapis.com/youtube/v3/comments?part=snippet&parentId=z12ei1s5gs2mc303523qsdigcxmphhlrd04&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
I receive an empty response:
Remarks
I have read Youtube Data API v3: commentThread call doesn't give replies for some comment threads , however, it does not provide me the answer as I do use the comments list with parentId and I am still not getting any replies.
Even if I try the not recommended way - using the part snippet,replies, I do not get any replies:
Request:
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&id=z12ei1s5gs2mc303523qsdigcxmphhlrd04&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
However, if I do not specify the comment thread by its ID and specify that I want all comment threads for the video:
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&videoId=xCLy2DZdXhY&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
Then voila - The comment thread is now with those two replies:
Why do I receive the replies now and not when I either specify the replies by their parentId or when I specify the comment thread by its id?
Moreover, if I take the (weird) id of one of the replies and try to obtain the comment with this reply, I will receive empty response:
GET https://www.googleapis.com/youtube/v3/comments?part=snippet&id=z12ei1s5gs2mc303523qsdigcxmphhlrd04.1443381718685326&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
Example 2
This problem is a bit different.
I have a video https://www.youtube.com/watch?v=-c76GeR2IWg with 7 comments (6 of them are top levels). When I try to obtain all top level comments related to this video I receive only 4 of them.
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&videoId=-c76GeR2IWg&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
One of the missing comments in the response is https://www.youtube.com/watch?v=-c76GeR2IWg&lc=z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k .
When I train to obtain comment thread with this id, I do obtain the comment thread:
GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&id=z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
And also, when I try to obtain the replies for this comment (there should be 1 reply) I receive an empty response:
GET https://www.googleapis.com/youtube/v3/comments?part=snippet&parentId=z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
Remarks
For both examples, the number of comments is less than the size of the page. For this simple example, I have skipped pagination and chose examples with only a few comments, in the real application I use the pagination but I do not get more results.
I do not really understand how is the YouTube and G+ integrated together, thus this might be the issue, however, I was always accesing these videos using only youtube, not checking the users' G+ page, thus I would say that this should not be the case.
Similar questions on SO:
How can I see all the comments with the Youtube API? This is about V2 API, thus no use for me.
Youtube Data API v3: commentThread call doesn't give replies for some comment threads This question is very similar and raises similar problems, however, it is exactly the other way around - The author does not receive all replies using the commentThread replies (which is agreeing with the documentation), however, the proposed solution is "Use the comments.listcall instead and specify the commentThread's ID for the parentId." - which is exactly what does not work for me.
YouTube Data API v3 Comment Thread Discrepency The author forgot about pagination.
YouTube Data API v3 - Comment threads request doesn't return all comments Similar question, yet without any answer.
When I do the following via HTTP request:
https://www.googleapis.com/youtube/v3/comments?part=snippet&parentId=z12ei1s5gs2mc303523qsdigcxmphhlrd04&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
I get the following response:
items": [
{
"kind": "youtube#comment",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/aOipn7OKd9ibVua9TWdtD2vJJgI\"",
"id": "z12ei1s5gs2mc303523qsdigcxmphhlrd04.1443381718685326",
"snippet": {
"textDisplay": "JM",
"parentId": "z12ei1s5gs2mc303523qsdigcxmphhlrd04",
"authorDisplayName": "Asia Price",
"authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UCtUuxM3_g2hWA7qr17d85RQ",
"authorChannelId": {
"value": "UCtUuxM3_g2hWA7qr17d85RQ"
},
"authorGoogleplusProfileUrl": "https://plus.google.com/100662746258967935686",
"canRate": false,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2015-09-27T19:21:58.685Z",
"updatedAt": "2015-09-27T19:21:58.685Z"
}
},
{
"kind": "youtube#comment",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/NtowtHGdhytzw9YY9RxUopEgoTA\"",
"id": "z12ei1s5gs2mc303523qsdigcxmphhlrd04.1443365800258222",
"snippet": {
"textDisplay": "0",
"parentId": "z12ei1s5gs2mc303523qsdigcxmphhlrd04",
"authorDisplayName": "FAY Fay",
"authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UC5b4dTxK4ae_roaMWMYpglQ",
"authorChannelId": {
"value": "UC5b4dTxK4ae_roaMWMYpglQ"
},
"authorGoogleplusProfileUrl": "https://plus.google.com/100517618639903741268",
"canRate": false,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2015-09-27T14:56:40.258Z",
"updatedAt": "2015-09-27T14:56:40.258Z"
}
}
I get the same results when I use the API explorer.
For your second example,
https://www.googleapis.com/youtube/v3/comments?part=snippet&parentId=z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k&fields=etag%2CeventId%2Citems%2Ckind%2CnextPageToken%2CpageInfo%2CtokenPagination%2CvisitorId&key={YOUR_API_KEY}
gives me
"items": [
{
"kind": "youtube#comment",
"etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/UBoqDwv8bg8xZpbIepzI_M5gp9o\"",
"id": "z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k.1409319325542384",
"snippet": {
"textDisplay": "Ahoj děkuju :) jo máš fajn videa :) ",
"parentId": "z120d11g2yyjyxcxw04cg1xbaqfnslfaamk0k",
"authorDisplayName": "Gumičkování s Péťou",
"authorProfileImageUrl": "https://lh4.googleusercontent.com/-VJce_PtJx70/AAAAAAAAAAI/AAAAAAAAABI/dabMtsy0haY/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UCAyuADHtiVTpiAbt2VVQhtQ",
"authorChannelId": {
"value": "UCAyuADHtiVTpiAbt2VVQhtQ"
},
"authorGoogleplusProfileUrl": "https://plus.google.com/101894467260220798842",
"canRate": false,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2014-08-29T13:35:25.542Z",
"updatedAt": "2014-08-29T13:35:25.542Z"
}
}
It might be an issue with your request or API key. Try making a new one and using that.

YouTube API - No channel branding settings returned for queries by username

When using the YouTube API v3 to query a channel's branding settings, why are they returned for queries by channel ID, but not for queries by username? The API doesn't return branding settings for channel list queries by username.
If you query for a channel's branding settings by channel ID (e.g., id=UC8-Th83bH_thdKZDJCrn88g), you are returned a complete set of branding settings:
Google API Explorer: https://developers.google.com/youtube/v3/docs/channels/list
Request
GET https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&id=UC8-Th83bH_thdKZDJCrn88g&key={YOUR_API_KEY}
Response
{
// ... snip ...
"items": [
{
"kind": "youtube#channel",
"etag": "\"...\"",
"id": "UC8-Th83bH_thdKZDJCrn88g",
"brandingSettings": {
"channel": {
"title": "The Tonight Show Starring Jimmy Fallon",
"description": "Watch The Tonight Show Starring Jimmy Fallon Weeknights 11:35/10:35c\n\nThe Tonight Show Starring Jimmy Fallon features hilarious highlights from the show including: comedy sketches, music parodies, celebrity interviews, ridiculous games, and, of course, Jimmy's Thank You Notes and hashtags! You'll also find behind the scenes videos and other great web exclusives.",
// all the branding settings are here
}
}
}]
}
If, on the other hand, you send a channel list query for a username (e.g., forUsername=latenight), you get no branding settings at all. The branding settings aren't returned or populated.
Request
GET https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&forUsername=latenight&key={YOUR_API_KEY}
Response
{
// ... snip ...
"items": [
{
"kind": "youtube#channel",
"etag": "\"...\"",
"id": "UC8-Th83bH_thdKZDJCrn88g"
}]
}
I may be wrong, but I believe that, in v3 of the APIs, Channel IDs are the only way to get a full response, as the concept of a "username" doesn't really exist in the same way anymore. That is, newly created YouTube channels are linked to a G+ profile and can have a display name, but there isn't really any YouTube username anymore associated with such a channel.
Because usernames used to exist, though, and many channels are still known by them, the "forUsername" parameter is there to provide you the associated channelID and then issue the request for the branding settings with that.
Now, having said that, it's clear that the language on the API explorer page doesn't reflect that, and perhaps therein lies the problem; I'm taking my inferences from this documentation:
https://developers.google.com/youtube/v3/guides/working_with_channel_ids#v3
and from this bug report:
https://code.google.com/p/gdata-issues/issues/detail?id=4821&q=forUsername&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary
But it's always possible, too, that I'm reading incorrectly and you're actually seeing a new bug. The only way to know for sure would be to file it (or perhaps someone on the team could comment here)?

Resources