YouTube Api playlist Video restricted to 50. How do I fetch more?
You need to add one extra query parameter pageToken
like below
private static String CHANNLE_GET_URL = "https://www.googleapis.com/youtube/v3/playlistItems" + "?part=snippet" + "&maxResults=50" + "&playlistId=PL-nbe4FPvDBElyW0Iww5suxJqqmuGBgIH" + "&key="+GOOGLE_YOUTUBE_API_KEY + "pageToken=" + NEXT_PAGE_TOKEN;//Pass like this one"https://www.googleapis.com/youtube/v3/search?part=snippet&order=date&channelId=UC2LrGJYe_uzI3FBj05BuvLA&key=AIzaSyBlj1dJ9txGcXOOblCJuQ0iwIkhUCgVt1Y&maxResults=50&pageToken=CJYBEAA"
and when you get data, you need to update NEXT_PAGE_TOKEN
by fetching value from nextPageToken
.
You will get data as
{ "kind": "youtube#searchListResponse", "etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/MgcKz6rwie5hyKKWdwMChcXzNzU\"", "nextPageToken": "CJYBEAA", "prevPageToken": "CGQQAQ", "regionCode": "IN", "pageInfo": { "totalResults": 184, "resultsPerPage": 50}, "items": [...]}
So, convert this data into JSONObject
as
JSONObject mainObject = new JSONObject(data);NEXT_PAGE_TOKEN = mainObject.getString("nextPageToken");...//Rest your task here
This works fine.