ded
ded

Reputation: 1

order - viewCount is showing wrong results in "YouTube API v3"

I am trying to get videos of a particular channel (like :- Luis Fonsi) in highest views order. And I am passing order parameter to sort the response by viewCount

like :-

order=viewCount

URL :-

https://www.googleapis.com/youtube/v3/search?key=[MY-API-KEY]&channelId=UCxoq-PAQeAdk_zyg8YS0JqA&part=snippet,id&order=viewCount&maxResults=20000

When I try to run it then It is not sorting as I expected. I was expecting first song would be Despacito But It got another one which definitely don't have the highest views.

As mentioned in Youtube-API Documentation in search section. viewCount – Resources are sorted from highest to lowest number of views.

It is not working like this.

I have tried many times but it is still not working.

Any help would be much Appreciated.

Upvotes: 0

Views: 535

Answers (1)

Benjamin Loison
Benjamin Loison

Reputation: 5612

YouTube Data API v3 is broken on some aspects, if I were you, I would just retrieve all videos from the given YouTube channel and then sort them.

To do so:

  1. Get the channel's uploads playlist id by using Channels: list with part=contentDetails.
  2. Get the channel's videos by using PlaylistItems: list with playlistId=UPLOADS_PLAYLIST_ID (replacing UPLOADS_PLAYLIST_ID with the one you just obtained).
  3. Get each video's view count by using part=statistics with Videos: list.

Upvotes: 0

Related Questions