YouTube API v3 Order Parameter Possible Bug - youtube-api

Looking at the YouTube API v3 Search documentation, it states that the order parameter is used to control ordering of API response resource results. However, when attempting to order by date, I'm not receiving the results in reverse chronological order as specified. In fact, they are not in any order whatsoever.
API Request with order date using API Explorer UI:
Is there some other way I should be requesting for results to be ordered by the time they were published on YouTube? Is there a bug in the handling of the order API parameter?

There's no bug; the 'order' parameter will sort results based on when the resources were created, This value may be slightly different than when a video is published, as a resource is created when an upload begins but a video is published when the upload finishes and is processed.
In this case, it looks like the 10 or so most recent videos were all uploaded at the exact same time (YouTube.com has a batch uploader), so you're getting the order they were created in, even though the published dates reflect minor differences (maybe a couple took a bit longer to upload or something). IF you scan the full list of results, though, you'll see they play out just fine in terms of their reverse chronological order. And generally you probably won't have so many videos that were batch uploaded like this.

Related

Playlist video API missed certain posts when ran on particular day

I use Youtube APIs to keep track of the brand assets of a certain channel.
Playlist API: https://www.googleapis.com/youtube/v3/playlistItems
There is a weekly refresh on the platform. In one of the refresh, playlist API missed a certain post in the corresponding week. Post published date was well within the range.
Any justifiable reason for this issue? Just want to get the root cause and probability for this issue to occur, so that I can build some safeguard on my platforms if required.
To my knowledge the result set obtained from PlaylistItems endpoint should be exact -- no fuzziness implied like in the case of Search endpoint. Therefore I am inclined to believe -- you did not provided actual data along with your question -- that there is something else that caused your issue.
Often users of the API overlook the fact that any video could first be uploaded as private and only later made public.
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.

YouTube API is not giving accurate video results

Getting video in the results even though it didn't match query parameter(q)
The parameter i passed didn't exists in body,title,tags, But the video is relavant. Is API looks any other metadata of video.
For Example: i have given parameter as "mobile", this video https://www.youtube.com/watch?v=j8UNo3vRIB0 is coming as result, here video title and description not contain mobile as parameter
Latest data not coming consistently in youtube api
Some times latest data not coming in youtube data api.
For Example: i have given rule as "amazon". This video https://www.youtube.com/watch?v=6zygd1iW-f4 is showing in youtube website's latest videos but not coming in youtube api result.
Example query: https://www.googleapis.com/youtube/v3/search?part=snippet&order=date&q=amazon&maxResults=50&type=video&key=xyz
W.r.t. point (1), Youtube is working OK, since the content of that video is related to the keyword mobile (please convince yourself by watching the first couple of minutes of that video).
For what concerns your point (2), I cannot in any way make the Youtube site to produce the video 6zygd1iW-f4 near the top of its search result set for the query term amazon.
All in all, I deem your claims above unsustainable.
Please note that one cannot expect crisp results from Youtube when queried with such general terms as yours is. One should not expect Youtube's searching feature to work similarly to say a full-text search in single computer-stored database. There will always be a degree of fuzziness associated to querying Youtube for broad terms.
You are actually stumbling on a very tricky scenario. Your goal is to get the same results via the API that you also see on YouTube’s website, right?
First, make sure that you configured the search endpoint as identical to your YouTube user account as possible:
order: relevance
relevanceLanguage: Same as the language that you set in the menu of YouTube’s website (Use a ISO 639-1 2-letter Code)
regionCode: Same as the country that you set in the menu of YouTube’s website (Use a ISO 3166-1 2-letter Code)
With these settings you will see that the results will be quite similar. But still not identical. Not because the API is not working or is still not properly configured but rather because YouTube’s search results change all the time. Just do the same exact search on YouTube’s website just 10 seconds apart. You’ll see that you get different search results.

Formating the api url to return only the videoId. (And use minimal quota)

So I'm using Home Assistant to launch an automation that retrieves the newest videoId that a channel has uploaded, so I can use my google home to play it(on a Roku TV), works fine, I am working on creating an automation that also does a GET request but for now, I am using the home assistant rest sensor that updates by performing a GET after a set number of seconds, for some reason though there are only 3 sensors polled every minute or so it seems they use around 100-500 quota(hitting my quota of 10,000 after only a few hours or less), I'm not sure if this is a home assistant problem or if I am not using the api correctly(I only need the videoId), ill link my url below:
https://www.googleapis.com/youtube/v3/search?key=API_KEY&part=id&order=date&maxResults=1
Expected 1-3 quota usage per GET, getting 100+ quota usage per GET.
Querying the Search Endpoint is more expensive than querying the PlaylistItems endpoint for the given user's uploads playlist. Depending on usage patterns, the default quotas may put rather tight limits on the number of calls an user is allowed to make on various endpoints of the API.
Adapting my answer to a different question, I suggest you to do the following instead: call PlaylistItems endpoint, passing to it as playlistId parameter the given channel's uploads playlist ID.
A given channel's uploads playlist ID is obtained upon querying the channel's own endpoint. The needed ID is to be found at .items.contentDetails.relatedPlaylists.uploads. Usually, an channel ID and its corresponding uploads playlist ID are related by s/^UC([0-9a-zA-Z_-]{22})$/UU\1/.
Note that you should query the Channels endpoint only once, then use the returned uploads playlist ID as many times as you need.
Also note that you may experiment using the fields parameter applied to your queries, as to get from the API partial resources only. However, I'm predicting that (I may well be wrong, since did not tested it) the cost of 3 points for querying PlaylistItems for its contentDetails object cannot be improved.
Here is a prototype URL:
https://www.googleapis.com/youtube/v3/playlistItems?key=APP_KEY&part=contentDetails&fields=items/contentDetails/videoId&maxResults=1&playlistId=PLAYLIST_ID

About YouTube search list API V3

In my application, I have used youtube.search.list API v3 for searching whole videos included in specific channel.
Example:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=[CHANNEL_ID]&q=[KEYWORD]
'q' is parameter for search keyword.
In my case, I used only 'q=' without keyword because I'd like to search whole videos.
It's working well at least until yesterday(27.Aug). but now, the server response is always 'totalResults: 0'
Could you tell me whether it's temporary wrong operation or the policy about this API is changed?
You can test above problem in the below url :
http://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet
The issue has been reported to the gdata issues list five times in the last 24 hours or so. Regardless of whether it's deliberate or not, there's a lot of people concerned.
The first instance report:
https://code.google.com/p/gdata-issues/issues/detail?id=6598

Pulling exhaustive watched video list from Youtube API (>1000 items)

I recently started exploring the Youtube API in order to pull some long-term data about what videos I've watched over the past year and when. I'm currently able to pull in my watched video list, but unfortunately I'm hitting the 1000 item cap. I think the issue is related to the ones found in Accessing an item beyond start_index=1000 in a YouTube user upload feed, where tweaking the request URL can change whether results are coming from the search cache or not.
Most of the similar questions on here deal with requesting urls that include some sort of sorting that would trigger the 1000 item cap, but I'm just running with basic URls such as https://gdata.youtube.com/feeds/api/users/default/watch_history?v=2&start-index=1000&max-results=49 . Why would I be encountering the caps?
For v3 the query quota adds up depending on how many returned items you have request or not being restrictive enough. Various query entries cost more and can multiple.
This might not apply for the OP but for the v3 API it is all layout in the reference. Maybe code in some quota keeping logic so you can get a better understanding.

Resources