Since the old feed on http://gdata.youtube.com/feeds/api/videos?author=[channel]&start-index=[index] is no longer available, I had to switch to the official YouTube API to get a list of all videos present on a channel. However, I've ran into the issue that this API does not return the right videocount on a channel. This also leads to being unable to use the pageToken, as none is returned.
The expected result is to have a an amount of 159 videos in total, however, at around 50% the API tells me there are only 16 videos.
I'm using the following url:
https://www.googleapis.com/youtube/v3/search?key=*****&channelId=UCsuBLfTDK4Hjn9Q6AYPwGqQ&part=snippet,id&order=date&maxResults=25
As 16 is lower than the max amount of results per request, I wont have a nextPageToken half of the time which I need to paginate and get a list of every record, making this API completely useless in production..
Is there anything I can do to resolve this issue, or is this a problem that lies on the YouTube side? Or is there anything else I can use as an alternative? All I need is the video IDs of every video on a certain channel.
First, get the ID for your uploads playlist:
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=CHANNEL_ID&key=API_KEY
The ID should be under 'uploads'.
Then, you can use the playlistItems list method:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PLAYLIST_ID&key=API_KEY
and get the number of videos from totalResults.
Alternatively, you can use the code from the playlistItems documentation
to get a list of the uploaded videos.
Related
I have tried to use the new YouTube API to get the videos with the highest view count of all time.
I have tried to use this request:
GET https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=10&order=viewCount&safeSearch=none&key={YOUR_API_KEY}
I thought it would work. It returns 10 videos that have a quite high view count and are sorted in a descending order by view count. However, those videos are definitely not the absolute top 10.
Is there a way to make YouTube API return the real top of most viewed videos?
I'm trying to retrieve all videos for a channel, and some are not being returned by the api. I cannot find anything in the spec that indicates why some would not be in the result set.
The call I'm making is:
https://www.googleapis.com/youtube/v3/search?type=video&key=__key_here__&channelId=UCxS2lX7728bTnmK1t21bYlA&part=id,snippet&maxResults=50&order=title
[To test this you'll need your own api key]
The first page of results is missing at least one video. The one from 8-15-2018, titled I LEARNED HOW TO DO A NEW TRICK!, which is located here, is not in the result set, even though it falls within the date range, and the first 50 results.
Does anyone know if this is a known issue?
I have verified that if I add the q parameter, with the video id, it will retrieve it.
You may refer with this link.
The API call that you should make if you want to get the videos in a channel is a youtube.playlistItems.list() with the playlistId of the "uploads" playlist for the channel. (This usually stars with UU..., but that's an implementation detail that might change in the future.
Here's an example of the call in the API Explorer.
Getting the same data via a search operation isn't guaranteed to return everything; the search index isn't a replacement for the backend data that you can obtain via the youtube.playlistItems.list() call. It's very much the same point raised in this blog post (though the focus there is on v2).
To summarize, to get all the uploads from a channel, you need to get the items from the uploads playlist for the channel using playlistItems.list on that playlist's ID rather than calling search.list on the channel ID.
I'm building a tool to help creators improve their Channel's activity/revenue/visibility/whatever.
One of the checks is about the videos being or not into a playlist.
For what I can see I can get the list of most recent video uploaded with the search.list then I thought to just call the playlistItem.list to verify if there is a match passing the videoId but instead I see that I need to pass a playlistId too at least. So this is not viable.
The only way seems to get all the playlist of the channel (playlist.list) and then get the last N items of every Playlist (with playlistItems.list) and then run some verification of these results locally.
Is this really the best possible solution?
I am currently working on a project, which tries to get all videoIds from the Upload-Playlist of the channel "PietSmiet" (a German Let's Player with around 15,500 videos).
Finding the Id of the channel ("UCqwGaUvq_l0RKszeHhZ5leA") and the Id of the Upload-Playlist ("UUqwGaUvq_l0RKszeHhZ5leA") is easy and getting the first fifty videos of this list is possible too.
I know that one can see more pages/videos by setting/changing the pageToken,
but on the 100th page (pageToken="CNYmEAA") there is no nextPageToken, despite the fact, that there are 15414 videos overall in the playlist and that this page only shows the videos 4950-4999.
By changing the pageToken to "CIcnEAA" (this page starts at the 4999th video), I could get to the 5048th video, but there is still no nextPageToken.
Is this a bug or a limitation and is there a solution?
I want to output last videos and popular videos of my youtube channel.
Is there any standart widget, api method for this?
Based on this answer, you can use the YouTube Data V3 API to get the uploads playlist ID, which you can then use to get the latest videos in that playlist. You can change the value of maxResults to return however many videos you want (from 0 to 50).
Use the search:list method to get your most viewed videos by specifying the channel ID and setting order=viewcount (not quite sure what you want when you say popular videos, you could also set order=rating to get the highest rated videos). This video might also help you out.