YouTube API V3 publishedAfter / publishedBefore not working - youtube-data-api

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.

Related

Youtube API, can I query videos filtering out channels?

I am writing queries to the Youtube Data v3 API and I want to see a list of videos that don't include videos by a certain channel. For example, a keyword search "iPhone" but not by Apple's channel. It doesn't work if I just do "-Apple" because that is filtering out the keyword versus the channel. Is there any way to do this?
Using as the query '"iPhone" -Apple"' removes all videos containing Apple (source), so it removes more than what you want but it does the job.
By the way Apple only uploaded 202 public videos as of today, so you could just exclude their channel id (UCE_M8A5yxnLfW0KghEeajjw) from the results you got with Search: list.

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 V3 api returns considerably different LIKEs and Comments results from numbers on the Web

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.

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 =.

Resources