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.
Related
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?
I wrote an application that uses YouTube Data API V3's search.list, which was able to pull active live streams for a specified channel (working since 2018) using the following:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCSJ4gkVC6NrvII8umztf0Ow&type=video&eventType=live&key={MYAPIKEY}
The above no longer returns any results for me as of September 12, 2019.
Broadening the search to all videos for a specified channel also no longer shows the active live stream:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCSJ4gkVC6NrvII8umztf0Ow&order=date&key={MYAPIKEY}
However, searching the ID of the active live stream itself works to return information about the video, which leads me to believe there may still be a way to accomplish this:
https://www.googleapis.com/youtube/v3/videos?part=snippet&id=hHW1oY26kxQ&key=
I am looking for a new solution that would be able to query a channel to see if they have an active live stream running, and grab the properties for that live stream.
It looks like something changed on google's end. Change 'channelId' to 'channelID' and it should work. Their documentation still says channelId, though, so maybe they are going to change it back.
Update: It seems the problem is fixed by Google, and it works as normal.
I got the same problem, the search API eventType=live gives no results anymore and coding it without eventType shows all videos including the live ones, but there's no way to sort it out because livebroadcastcontent says none even if it is a live one. I hope it's a temporary failure. Changing channelId to channelId doesn't do the thing.
I got a temporary solution as follows. Remove channelId and use a keyword instead q=... this returns a live broadcast. It's not the best or most handy solution, but it helped me a bit. I think YouTube has to solve our problem n with eventType-live for a channelId it still doesn't work.
Your kind of search query (that is relative to a given channel) can be replaced with a proper query to the respective channel's uploads playlist.
Upon doing that, do query the Videos endpoint for the set of videos that you determined to be newly added (via the previous call you did to the PlaylistItems endpoint).
For each such video, then reach for the property liveBroadcastContent.
There is definitely something going on with the YouTube Data API. If you give it a try on the on the Deverloper Console for Search: list it won't work if you are providing channelId. However, if you provide channelId it will always return 0 results. I've tried this with several other channels who are live streaming right now.
There are several other people posting about this same issue. So we are not the only ones experiencing this issue. Google needs to fix something.
I hope my contribution isn't coming too late. I had the same issue, when my query (q) was left at news, but the moment i changed it to a term common to my channel uploads, i got the right response. part=snippet&type=video&event_type=live&channel_id=****&key=******&q=[youchanneltitleorkeyword]
I need help on calling Services > YouTube Data API v3 > youtube.search.list. I tried several times a few days ago and it worked just fine. Today, it does not return correct year. It included 2016.
part - snippet
channelid - UC-lHJZR3Gqxm24_Vd_AJ5Yw
publishedAfter - 2018-12-17T16:05:58.000Z
publishedBefore - 2018-12-20T16:05:58.000Z
Because Search: list can only retrieve channels, videos and playlists according to type parameter, I assume that by specifying a channelId you are looking for videos and playlists during a given period of time of a given YouTube channel.
Playlists are easily retrievable with https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UC-lHJZR3Gqxm24_Vd_AJ5Yw&key=YOUR_API_KEY.
And about videos because Search: list isn't reliable I would recommend you to get all videos for the given YouTube channel and then proceed to your sort on your own. I would recommend you to use this approach to retrieve all YouTube videos of a given YouTube channel. The approach consists in getting the uploads auto-created playlist id of the YouTube channel by using Channels: list with contentDetails in part and then use PlaylistItems: list to retrieve all public videos uploaded on this YouTube channel.
YouTube v3 api returns significantly different LIKEs count from what is on the web version of YouTube.
Compare these:
https://monosnap.com/file/EdtDNTTGDK06zoCZ7IXkMdzn6WuyOo
https://monosnap.com/file/CcJOiKl9CBMyncHQSrPv3lkLOuqeDD
To replicate:
https://www.googleapis.com/youtube/v3/videos?id=jWnhFM1Ttwg&key={api_key}&maxResults=50&part=statistics (https://console.developers.google.com/apis/credentials - use your Youtube V3 key)
Any ideas?
Many thanks!
Since I don't have any documentation (from the YouTube Data API v3) that backs me up for what I going to say, I'll drop some thoughts about why the API returns different values in the "likeCount" section comparing to the YouTube actual video (saw in the main website):
I think that the differences in the results returned by the API and the results shown in the website are due to:
YouTube has its own calculations for set the values in the website, the API results and in the YouTube Analytics1.
It would be possible that those additional "likes" retrieved in the API aren't exposed to the calculations made by YouTube.
1 Extracted from this answer in the Google Support webpage:
The number of likes/dislikes in YouTube Analytics may be different than what you see on the watch page under the video. This
is a known issue and our team is working to fix this. In the meantime,
please refer to the counts on the watch page under the video for the most accurate count.
And
In rare instances, you might see more likes/dislikes than views since these metrics are adjusted by different verification
systems.
For the specific videoId you posted in your question, I did check at 2019-01-25 and the results were:
likeCount "by the API": 1341
likeCount "in the YouTube website": 851
Check again at 2019-01-28 the numbers did changed:
likeCount "by the API": 1367
likeCount "in the YouTube website": 877
You can try here the API request for get these results - (results for current day).
If you make a substract from the likeCount values gotten above, you'll get 26.
Maybe it is futile try make any mathematical operation for set the "correct" value shown in the YouTube website (using the likeCount result from the YouTube Data API), but if anyone want give it a try, I encourage you to share your answer.
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.