Reputation: 39
I use folowwing code to list Channel's video:
String URL="https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=25&key={Your_API_KEY}";
It works well, lists 50 videos from my channel. Now i want to list my playlist's videos. I tried following code adding 'playlistId':
String URL="https://www.googleapis.com/youtube/v3/search?part=snippet&playlistId={PLAYLIST_ID}&maxResults=25&key={Your_API_KEY}";
But it doesn't work....any ideas ?
Upvotes: 2
Views: 2040
Reputation: 31417
First add Youtube dependency in your build.gradle
:
compile 'com.google.apis:google-api-services-youtube:v3-rev189-1.23.0'
For me it seems wrong url for playlist. Google Developer has shared sample code for listing playlist video of specific playlist of all playlist video of specific channel. Here is sample snippet for listing video from specific playlist.
YouTube youtube = getYouTubeService();
try {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("part", "snippet,contentDetails");
parameters.put("maxResults", "25");
parameters.put("playlistId", "PLBCF2DAC6FFB574DE");
YouTube.PlaylistItems.List playlistItemsListByPlaylistIdRequest = youtube.playlistItems().list(parameters.get("part").toString());
if (parameters.containsKey("maxResults")) {
playlistItemsListByPlaylistIdRequest.setMaxResults(Long.parseLong(parameters.get("maxResults").toString()));
}
if (parameters.containsKey("playlistId") && parameters.get("playlistId") != "") {
playlistItemsListByPlaylistIdRequest.setPlaylistId(parameters.get("playlistId").toString());
}
PlaylistItemListResponse response = playlistItemsListByPlaylistIdRequest.execute();
System.out.println(response);
}
Or, as per your current implementation, change url as below
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId={PLAYLIST_ID}&key={MY_API_KEY}
Upvotes: 2
Reputation: 964
I believe you are looking for the playlist API request instead of search.
String URL = "https://www.googleapis.com/youtube/v3/playlists?part=snippet&id={PLAYLIST_ID}&maxResults=25&key={Your_API_KEY}";
Reference: https://developers.google.com/youtube/v3/docs/playlists/list
Upvotes: -1