Question

I've got a problem by using the API: https://developers.google.com/youtube/v3/docs/search/list#try-it.

I would like to order my results by rating. Therefore, I set the "order" parameter's value to "rating". As returned result, I just receive videos with low likes and/or dislikes and it is not ordered by rating. Even when I just try it in the API Explorer I get the same results, so it can't be because of my code.

Is there a problem with the API or do I understand the value "rating" wrong?

Was it helpful?

Solution

The V3 API returns the same results you'd get by performing a search on the YouTube site and setting the 'Sort by' filter to Rating eg.

https://www.googleapis.com/youtube/v3/search/?q=stackoverflow&order=rating&part=snippet
https://www.youtube.com/results?search_sort=video_avg_rating&search_query=stackoverflow

The key point is that it's an average rating, not based only on likes.

The API defines getRating as -

Retrieves the ratings that the authorized user gave to a list of specified videos.

so it would seem the average takes into account likes and dislikes. It's not immediately clear whether the 1-5 rating system (from YouTube V2 API) or any other data is also used?

If you just wish to obtain the like count, you can make another API request with your video ID's that returns separate counts for like, dislike, none and unspecified -

https://www.googleapis.com/youtube/v3/videos/getRating?id=XXXXXXX,XXXXXXX
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top