Problem with YouTube Data Api PlaylistItems: list. Why video duplicates in pagination? - youtube-data-api

I am trying to get list of all videos in a playlist.
I am using request to the API https://youtube.googleapis.com/youtube/v3/playlistItems with parameters part=contentDetails, maxResults=50, playlistId=***, pageToken=***
But here is the problem: the same video appears on different pages on pagination.
I am trying to do this action several times but some videos always duplicates.
I even try to do all request in Postman step by step just if there is error in my code but result is the same.

Related

Youtube API v3 PlaylistItem return only first 100 items of playlist since 18.07.20 for some channels

I am working on a web-app which use Youtube API for marketing research and recently we stuck a strange change in Youtube API work.
I am getting a channel videos with the help of code which was getting videos from channel upload playlist. I take a channelId, transform it to this channel upload playlist playlistID and with youtube youtube-api v3 playlistItem method list videos from it, page by page(50 results per page).
And previously there was no problems with it. But recently, around 18.07.20, for some channels this method have stopped to work properly.
If previously I could get this way thousand or even more videos, now some channels are limited to barely 100 videos or 2 pages. And there is no changes in Youtube API documentation or in revision history regarding this.
For example, here is example of such behavior.
Example Channel: https://www.youtube.com/user/WWEFanNation
Channels video count: 48,582
Channels ID: UCJ5v_MCY6GNUBTO8-D3XoAg
Channels upload playlistId: UUJ5v_MCY6GNUBTO8-D3XoAg
First request:
https://developers.google.com/youtube/v3/docs/playlistItems/list?apix=true&apix_params=%7B%22part%22%3A%5B%22snippet%22%5D%2C%22maxResults%22%3A50%2C%22playlistId%22%3A%22UUJ5v_MCY6GNUBTO8-D3XoAg%22%7D
Code 200, results items 50
Second request:
https://developers.google.com/youtube/v3/docs/playlistItems/list?apix=true&apix_params=%7B%22part%22%3A%5B%22snippet%22%5D%2C%22maxResults%22%3A50%2C%22pageToken%22%3A%22CDIQAA%22%2C%22playlistId%22%3A%22UUJ5v_MCY6GNUBTO8-D3XoAg%22%7D
Code 200, results items 50
Third request:
https://developers.google.com/youtube/v3/docs/playlistItems/list?apix=true&apix_params=%7B%22part%22%3A%5B%22snippet%22%5D%2C%22maxResults%22%3A50%2C%22pageToken%22%3A%22CGQQAA%22%2C%22playlistId%22%3A%22UUJ5v_MCY6GNUBTO8-D3XoAg%22%7D
Code 200, results items 0. Page don`t have results, but have a nextPageToken. All next pages, at least 20, are empty.
And this happening with pretty much 50% of channels. Some channels can give back full list of 400 videos+, other give back only part of videos or limited by 100 results.
I have tried in meantime to use https://developers.google.com/youtube/v3/docs/search/list for channelId, but it give back not all videos, but most relevant. And can miss alot of videos because of it.
This especially frustrating because there was no changes in documentation, so it is absolutely unclear why some channels are caped, while other are not.
So questions is:
Does anybody know what is happening?
Is there another way to consistently get all videos for channel sorted by upload date?

Youtube API v3 get every Video ID from given channel

Currently I'm using this in order to get a list of videoIDs from a given channel:
GET https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=CHANNEL_ID&type=video&maxResults=50&key=API_KEY
This works, however the channel I want to get the videos from has a lot more than 50 Videos online. I already looked at this issue YouTube API to fetch all videos on a channel but every solution again online fetches 50 Videos max.
How can I get every video and not just 50?
So I got a solution:
(1) First, I use https://www.googleapis.com/youtube/v3/channels?id=CHANNEL_ID&key=API_KEY&part=contentDetails to get the id of the Uploads Playlist.
(2) By using https://www.googleapis.com/youtube/v3/playlistItems?playlistId=UPLOAD_ID&key=API_KEY&part=snippet&maxResults=50
I get the first 50 results and a pageToken.
(3) With the token I can collect the IDs from the next pages:
https://www.googleapis.com/youtube/v3/playlistItems?playlistId=UPLOAD_ID&key=API_KEY&part=snippet&pageToken=PAGE_TOKEN&maxResults=50
(4) By using a recursive method, I can use the next Token I get from (3) to scan the next page.
Here's a video from the YouTube Developers channel that really helped me with this: https://youtu.be/RjUlmco7v2M. It's directed towards people migrating from v2 to v3 (which I wasn't), but I kept watching and learned quite a few things.

YouTube videos stats using Google API YouTube Analytics in one request

Is it possible to get daily video stats for X videos at once?
YT Analytics API does stats only for a channel. Of course I can filter results by video ID (but only one!). I'm getting an error while trying to put "video=1;video=2;video=3" in filter method.
From the documentation of the reports.query endpoint of the YouTube Analytics API, assuming this is the endpoint you are referring to:
The API supports the ability to specify multiple values for the video, playlist, and channel filters. To do so, specify a separated list of the video, playlist, or channel IDs for which the API response should be filtered. For example, a filters parameter value of video==pd1FJh59zxQ,Zhawgd0REhA;country==IT restricts the result set to include data for the given videos in Italy. The parameter value can specify up to 200 IDs.
In other words: only use commas between video IDs (not semicolons), don't repeat the video keyword for each ID and use == instead of =.

in the v3 api, how can i list the most recent items?

My app needs to sync up with the youtube api to pull in info about any new videos. But in the PlaylistItems.list docs, I don't see any kind of "sort order" or date filtering parameters.
Is there a way to do this, or do I need to download all the playlist items every time I want to check if there is a new video?
You are going to have to download the playlist your self and then sort them locally. As you have already seen there is no way to sort them or filter the number of rows.
I think there is a really old feature request for the ability to sort. Playlist API: Add support for sorting playlist items response
What I find interesting is that they still haven't done more then set the status to "Acknowledged" and it took them two years to do that.
I guess this goes back to the question I always have who's responsibility is it to sort the data? The API or the developer? It appears that Google thinks its the developer.
I found a post on my travels that said that all play lists generated are ordered from newest first to oldest. Excepting personal playlists that the user creates which are ordered as they were added. So first added will be first in list. So [0] node is first in list response.
On the other hand, you can use the [publishedAt] property to get a time stamp.
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=.........
[snippet] => Array ([publishedAt]=> 2010-05-12T23:57:34.000Z
Or
https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=........
However please note, this call will give EVERYTHING from the channel. Video uploads and playlists created.
As there are many call possibilities in the api, I am sure that you can find the right one that works for your needs.

Youtube video search result sorting order does not match with youtube.com

Youtube data API v3:
Youtube data api v3 does not return video list in the same order as youtube.com when searching with a specific query like "old hindi songs"
Why??
There can be many reasons for this. But this doesn't mean that you're doing something wrong. It's supposed to be this way.
For example if you are logged in in youtube, youtube will order the results taking in account videos you watched or liked, while the data api does not have access to this info. Also it may filter the results based on your region, while the api will filter by region only if specifically told so.
Try running your browser in incognito, don't log in into youtube, and perform from there a youtube search. The results should 90% match those received from api v3 if of course your request to the api has the order parameter set to relevance.

Resources