I have tried to use the new YouTube API to get the videos with the highest view count of all time.
I have tried to use this request:
GET https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=10&order=viewCount&safeSearch=none&key={YOUR_API_KEY}
I thought it would work. It returns 10 videos that have a quite high view count and are sorted in a descending order by view count. However, those videos are definitely not the absolute top 10.
Is there a way to make YouTube API return the real top of most viewed videos?
Related
Does anyone know how this website is able to get historical views data for YouTube playlists?
From my research, YouTube API doesn't even let you get the current playlist views (I might be wrong).
I am talking about the playlist views, not the views from videos that were added to the playlist (you can see the view count here for example, on the left side - on desktop).
How can we get access to this type of data?
One more time YouTube Data API v3 doesn't provide a basic feature.
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/playlists?part=statistics&id=PLAYLIST_ID containing item["statistics"]["viewCount"] integer, your problem is solved.
You can request up to maxResults (currently 50) playlists separating playlist ids by a comma in id, example: https://yt.lemnoslife.com/playlists?part=statistics&id=PLAYLIST_ID_0,PLAYLIST_ID_1,...,PLAYLIST_ID_49
You can also request the title of the playlist by adding snippet to part, example: https://yt.lemnoslife.com/playlists?part=snippet,statistics&id=PLAYLIST_ID
I am currently working on a project, which tries to get all videoIds from the Upload-Playlist of the channel "PietSmiet" (a German Let's Player with around 15,500 videos).
Finding the Id of the channel ("UCqwGaUvq_l0RKszeHhZ5leA") and the Id of the Upload-Playlist ("UUqwGaUvq_l0RKszeHhZ5leA") is easy and getting the first fifty videos of this list is possible too.
I know that one can see more pages/videos by setting/changing the pageToken,
but on the 100th page (pageToken="CNYmEAA") there is no nextPageToken, despite the fact, that there are 15414 videos overall in the playlist and that this page only shows the videos 4950-4999.
By changing the pageToken to "CIcnEAA" (this page starts at the 4999th video), I could get to the 5048th video, but there is still no nextPageToken.
Is this a bug or a limitation and is there a solution?
I want to output last videos and popular videos of my youtube channel.
Is there any standart widget, api method for this?
Based on this answer, you can use the YouTube Data V3 API to get the uploads playlist ID, which you can then use to get the latest videos in that playlist. You can change the value of maxResults to return however many videos you want (from 0 to 50).
Use the search:list method to get your most viewed videos by specifying the channel ID and setting order=viewcount (not quite sure what you want when you say popular videos, you could also set order=rating to get the highest rated videos). This video might also help you out.
Since the old feed on http://gdata.youtube.com/feeds/api/videos?author=[channel]&start-index=[index] is no longer available, I had to switch to the official YouTube API to get a list of all videos present on a channel. However, I've ran into the issue that this API does not return the right videocount on a channel. This also leads to being unable to use the pageToken, as none is returned.
The expected result is to have a an amount of 159 videos in total, however, at around 50% the API tells me there are only 16 videos.
I'm using the following url:
https://www.googleapis.com/youtube/v3/search?key=*****&channelId=UCsuBLfTDK4Hjn9Q6AYPwGqQ&part=snippet,id&order=date&maxResults=25
As 16 is lower than the max amount of results per request, I wont have a nextPageToken half of the time which I need to paginate and get a list of every record, making this API completely useless in production..
Is there anything I can do to resolve this issue, or is this a problem that lies on the YouTube side? Or is there anything else I can use as an alternative? All I need is the video IDs of every video on a certain channel.
First, get the ID for your uploads playlist:
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=CHANNEL_ID&key=API_KEY
The ID should be under 'uploads'.
Then, you can use the playlistItems list method:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PLAYLIST_ID&key=API_KEY
and get the number of videos from totalResults.
Alternatively, you can use the code from the playlistItems documentation
to get a list of the uploaded videos.
When using the YouTube api to query and retrieve videos, is there a way to limit results only official content? I want to retrieve the new music videos for certain artists but I want to make sure I am only receiving real videos and not UGC stuff. Can this be accomplished? Thank you.
There is no search parameter that ensures that you only get back "real" music videos. (And the line between a "real" video and user-generated content isn't always clear.)