Is there a way to get a list of Youtube videos sorted by view count - youtube

I am trying to collect a large list of YouTube's most watched videos for a data science application. I tried to use the YouTube Data API with the following query:
https://www.googleapis.com/youtube/v3/search&order=viewCount&type=video&regionCode=US&key=API_KEY,
but it does not seem to give me the same video ideas as in this list: https://en.wikipedia.org/wiki/List_of_most-viewed_YouTube_videos
Could someone tell me how I should do it?

Using the Search.list API endpoint is one way to search for the most viewed videos pertaining to a given region.
There's another endpoint -- Videos.list -- that, when queried with chart set to mostPopular, gives back:
chart (string)
The chart parameter identifies the chart that you want to retrieve.
Acceptable values are:
mostPopular – Return the most popular videos for the specified content region and video category.
As per the specification of videoCategoryId:
By default, charts are not restricted to a particular category.
Therefore, you may safely invoke Videos.list with chart=mostPopular and regionCode=US, without passing to it any videoCategoryId.
These two are the only API means that accomplish the task described by your post.

Related

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.

YouTube API v3 Search not returning all 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.

Including topics in search results

I'm interested in getting topics as part of the results when searching with:
https://www.googleapis.com/youtube/v3/search?
For instance, when searching Dance Music on the YouTube website, it shows some videos and on the side there's a Electronic Dance Music topic showing up.
How can I get that using the API?
I'll also be fine search for topics in a different API call.
Use the Search: list method which returns a collection of search results that match the query parameters specified in the API request. By default, a search result set identifies matching video, channel, and playlist resources, but you can also configure queries to only retrieve a specific type of resource such as the topicId parameter.
The topicId parameter indicates that the API response should only contain resources associated with the specified topic. The value identifies a Freebase topic ID.
Important: Due to the deprecation of Freebase and the Freebase API, the topicId parameter started working differently as of February 27, 2017. At that time, YouTube started supporting a small set of curated topic IDs, and you can only use that smaller set of IDs as values for this parameter.
You may use the API Explorer to try the sample request.

Youtube API v3 Return Lat/Lng

I can search lat/long with YouTube v3 successfully,
https://www.googleapis.com/youtube/v3/search?part=snippet,id&maxResults=50&type=video& videoType=any&key=foobar&location=40.7127,74.0059&locationRadius=100km
However, the response doesnt give me the individual videos lat/lng in the results.
The API doc says:
The part parameter specifies a comma-separated list of one or more
search resource properties that the API response will include. Set the
parameter value to snippet.
I cannot find any other search resource properties besides id and snippet in Search:list.
(Why would the API include that first sentence if there are only 2 options?) I digress.
Question-
Is there any way that I can retrieve YT videos lat/long based on lat/long search?
You can have lat/long parameters of the videos you own or manage. But due to privacy reasons (been able to locate people from their uploads.) you won't be able to get specific geolocations of other people's uploads.

Obtain analytical data for a specific video within a date range

So after scouring the youtube API, and thinking that this may not be possible, I'll give a last try here.
In a nutshell, I am trying to obtain analytical data from youtube's analytics's API for specific videos for a date range (by day if possible). I've found ways to get the channel data that the video reside in, but I have been unable to find how to ontain the specific video data itself. Assuming it exists in v3 that is.
Anyone had any luck with this kind of task at all? Has this feature been developed for v3 as of yet?
Channel Reports is the API to retrieve video metrics. It can filter by video, by country, by lead (for some fields) and accepts timespan and data aggregation granularity. In brief, Available Reports lists all the valid query parameter combinations.
Individual comments can be retrieved with v2 Data API - together with their dates.

Resources