i'm trying to get certain order from youtube videos on my Android application. I want to search, for example:
Fight 1
Fight 2
Fight 3
Fight 4
This is my search list:
YouTube.Search.List search = mYouTubeDataApi.search().list("id,snippet");
search.setKey(ApiKey.YOUTUBE_API_KEY);
search.setQ(mTitle + " " + mSearchQuery);
search.setType("video");
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
search.setMaxResults(YOUTUBE_PLAYLIST_MAX_RESULTS);
searchResponse = search.execute();
So far, i've tried adding to my Search List:
search.setOrder("title");
and also i tried to sort manually the items this way
List<Video> items = videoListResponse.getItems();
Collections.sort(items, new Comparator<Video>() {
@Override
public int compare(Video video, Video t1) {
return video.getSnippet().getTitle().compareToIgnoreCase(t1.getSnippet().getTitle());
}
});
return new Pair(searchResponse.getNextPageToken(), items);
but i still don't get the results as i expect, and my sort is not good (i.e.: fight 1, fight 10, fight 11, fight 2, etc...)
Thanks in advance!
You can use Search: list using the HTTP request:
GET https://www.googleapis.com/youtube/v3/search
with the optional parameter order added to the query.
As discussed in the documentation,
The order parameter specifies the method that will be used to order resources in the API response.
Acceptable values are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With