我有一个YouTube帐户,里面有4个频道。我在所有频道中创建了私人和公共播放列表,但是当我试图通过OAuth流程获取私人播放列表时,我无法获取私人播放列表ID,只显示公共播放列表。即使我尝试过api explorer我也能看到只有公共播放列表不是私有的以下是我的代码请帮帮我
Credential credential = getCredentials();
youTube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("Playlist Web App").build();
String channelID = getDefaultChannelId();
YouTube.Search.List search = youTube.search().list("id,snippet");
search.setChannelId(channelID);
search.setType("playlist");
search.setFields("items(id/playlistId,kind,snippet(title))");
search.setMaxResults((long) 10);
SearchListResponse searchResponse = search.execute();
List<SearchResult> searchResultList = searchResponse.getItems();
if (searchResultList != null) {
Iterator<SearchResult> iteratorSearchResults = searchResultList.iterator();
if (!iteratorSearchResults.hasNext()) {
System.out.println(" There aren't any results for your query.");
}
while (iteratorSearchResults.hasNext()) {
SearchResult playlist = iteratorSearchResults.next();
ResourceId rId = playlist.getId();
System.out.println(" Playlist Id : " + playlist.getId().getPlaylistId());
System.out.println(" Title: " + playlist.getSnippet().getTitle());
}
}
我遵循OAuth流程,但我无法获得自己的私人播放列表。
答案 0 :(得分:2)
是的,我现在能够获得我频道的私人播放列表。
而不是YouTube.Search.List search = youTube.search().list("id,snippet");
和设置search.setType("playlist");
最好去YouTube.Playlists.List。下面分享我可能对其他人有用的代码
Credential credential = getCredentials();
youTube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("Playlist Web App").build();
YouTube.Playlists.List searchList = youTube.playlists().list("id,snippet,contentDetails");
searchList.setFields("etag,eventId,items(contentDetails,etag,id,kind,player,snippet,status),kind,nextPageToken,pageInfo,prevPageToken,tokenPagination");
searchList.setMine(true);
searchList.setMaxResults((long) 10);
PlaylistListResponse playListResponse = searchList.execute();
List<Playlist> playlists = playListResponse.getItems();
if (playlists != null) {
Iterator<Playlist> iteratorPlaylistResults = playlists.iterator();
if (!iteratorPlaylistResults.hasNext()) {
System.out.println(" There aren't any results for your query.");
}
while (iteratorPlaylistResults.hasNext()) {
Playlist playlist = iteratorPlaylistResults.next();
System.out.println(" Playlist Id : " + playlist.getId());
System.out.println(" Title: " + playlist.getSnippet().getTitle());
}
}
要获得更多YouTube服务,请访问以下https://developers.google.com/apis-explorer/#p/youtube/v3/