The YouTube API v3 can return the videoCategory of a video. For example, if you make the following request:
www.googleapis.com/youtube/v3/videos?id=ZCJgvabihQ8&key=apiKey&part=snippet,recordingDetails
You will find that the video with id ZCJgvabihQ8 belongs to Category 24. But how can I get the guideCategory id instead of the videoCategory id?
from the Doc
https://developers.google.com/youtube/v3/docs/guideCategories
A guideCategory resource identifies a category that YouTube algorithmically assigns based on a channel's content or other indicators, such as the channel's popularity. The list is similar to video categories, with the difference being that a video's uploader can assign a video category but only YouTube can assign a channel category.
The guideCategory is assigned to a channel, not to a video, and I believe that can be used only to list channels
Related
I am trying to get videos of a particular channel (like :- Luis Fonsi) in highest views order. And I am passing order parameter to sort the response by viewCount
like :-
order=viewCount
URL :-
https://www.googleapis.com/youtube/v3/search?key=[MY-API-KEY]&channelId=UCxoq-PAQeAdk_zyg8YS0JqA&part=snippet,id&order=viewCount&maxResults=20000
When I try to run it then It is not sorting as I expected. I was expecting first song would be Despacito But It got another one which definitely don't have the highest views.
As mentioned in Youtube-API Documentation in search section.
viewCount – Resources are sorted from highest to lowest number of views.
It is not working like this.
I have tried many times but it is still not working.
Any help would be much Appreciated.
YouTube Data API v3 is broken on some aspects, if I were you, I would just retrieve all videos from the given YouTube channel and then sort them.
To do so:
Get the channel's uploads playlist id by using Channels: list with part=contentDetails.
Get the channel's videos by using PlaylistItems:
list
with playlistId=UPLOADS_PLAYLIST_ID (replacing
UPLOADS_PLAYLIST_ID with the one you just obtained).
Get each
video's view count by using part=statistics with Videos:
list.
I have tested YouTube's PlaylistItems.list API to fetch a channel's default playlist.
In the response payload, a video -- that was published on 2020-10-14T20:22:24Z -- is in the first object, and then the next video -- that was published on 2020-10-21T17:54:05Z -- is in the second object.
In this answer it is mentioned that:
The publishedAt getting returned from a Playlist query is the date the
video was added to the playlist, rather than the date the video was
published on YouTube
What might be the reason for my case?
Is there any specific sorting order maintained for this API?
The reason you see the ordering you've exemplified (though you did not mentioned your playlist ID such that others to verify your claim) is two fold.
1. A video's publication time may well be different than its upload time
First thing is the following: according to the official docs of the Video resource's publishedAt property (the emphasis below is mine):
snippet.publishedAt (datetime)
The date and time that the video was published. Note that this time might be different than the time that the video was uploaded. For example, if a video is uploaded as a private video and then made public at a later time, this property will specify the time that the video was made public.
There are a couple of special cases:
If a video is uploaded as a private video and the video metadata is retrieved by the channel owner, then the property value specifies the date and time that the video was uploaded.
If a video is uploaded as an unlisted video, the property value also specifies the date and time that the video was uploaded. In this case, anyone who knows the video's unique video ID can retrieve the video metadata.
The value is specified in ISO 8601 format.
Therefore, in cases, it may very well be that a given video has different upload time and time of publication.
Furthermore, the official docs of PlaylistItems resource says the following w.r.t. two related properties:
snippet.publishedAt (datetime)
The date and time that the item was added to the playlist. The value is specified in ISO 8601 format.
contentDetails.videoPublishedAt (datetime)
The date and time that the video was published to YouTube. The value is specified in ISO 8601 format.
From the spec of snippet.publishedAt, it follows that, in the case of a playlist being the uploads playlist of a given channel (that is a playlist of which ID is of form UU...; note that, usually, a channel ID and its corresponding uploads playlist ID are related by s/^UC([0-9a-zA-Z_-]{22})$/UU\1/, though not documented officially), the value of snippet.publishedAt is the upload date of that video.
The second spec, indicates that the value of contentDetails.videoPublishedAt is that of the corresponding Video resource's snippet.publishedAt, the time of publication of that video.
2. For the uploads playlist of a channel, the items returned by PlaylistItems.list API endpoint are (have to be) ordered in reverse chronological order by contentDetails.videoPublishedAt
Indeed, the ordering condition seems to be true. This feature is not documented officially, but, in my experience, the statement above holds true for every result set obtained from PlaylistItems.list endpoint.
I could make here the following argument justifying the necessity that the items resulted upon the invocation of PlaylistItems.list endpoint be ordered in reverse chronological order (newest first) by contentDetails.videoPublishedAt:
This argument is of a pragmatic kind: if the result set of PlaylistItems.list is not ordered as mentioned, then this endpoint becomes useless.
This is so, since, in this case, for one to obtain the most recently published video would have to fetch locally all the uploaded items (the number of which is limited by design to 20000), for to then scan that result set for the most recent one. Being compelled to fetch all uploaded items only for to obtain the newest one is pragmatically a nonsense. If the number of uploads of a given channel exceeds the limit of 20000, then the most recent video could possibly fall outside this boundary; thus, for such kind of channels, the most recently published video could not be obtained from the API at all.
Therefore, by way of contradiction, the result set has to be ordered in reverse chronological order by contentDetails.videoPublishedAt.
How to get all list youtube channel by API? Popular, categories...
ex:
Music
Sport
News
BostonEnglish
etc
Im not sure if there's a category for Boston English. But, for the general categories you've mentioned like Music, News, Sports, there's definitely a way to do that. Use this list as video category guide.
Try this on your browser:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&videoCategoryId=17&maxResults=50&key=SERVER_API_KEY_HERE
It will show you a list of channels under Sports.
Just change the videoCategoryId=17 part depending on which category you like. So if it's music, use videoCategoryId=10 and so on. maxResults=50 is set to 50, meaning it will display 50 results per page
I want to get all the videos from a playlist with statistics data like viewCount and the videos should be ordered by number of video views. So far I have managed the following:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUbW18JZRgko_mOGm5er8Yzg&key={YOUR_KEY_HERE}&maxResults=50
In the youtube api v2 we can pass part=statistics to get the view count but this is not working with v3 playlists. How can I get the above the video data in the above mentioned format.
From the results of playlistItems.list call, collect the video ids, make a comma-separated list and set it as id parameter of videos.list call. That call will give you the data you need.
I am using the Youtube v3 api (video list function) to retrieve the statistics for some videos uploaded by a client. I filter the list by the video ids.
Does anyone have any idea how long the "id" parameter could be for such request? The reference only states this:
id - string - The id parameter specifies a comma-separated list of the YouTube video ID(s) for the resource(s) that are being retrieved. In a video resource, the id property specifies the video's ID.
In theory 50 IDs... you technically can only query 50 videos at a time, so unless you use next page tokens and keep the IDs, you're limited to 50... Personally I wouldn't go above 50 at a time...