Java 如何通过YouTube API V3获取私有播放列表ID?
我有一个YouTube帐户,其中有4个频道。我在所有频道中创建了私有和公共播放列表,但当我试图通过OAuth进程获取私有播放列表时,我无法获取私有播放列表ID,只有公共播放列表显示。即使我尝试了api explorer,我也能看到下面唯一非私有的公共播放列表是我的代码,请帮助我Java 如何通过YouTube API V3获取私有播放列表ID?,java,api,youtube,youtube-api,youtube-data-api,Java,Api,Youtube,Youtube Api,Youtube Data Api,我有一个YouTube帐户,其中有4个频道。我在所有频道中创建了私有和公共播放列表,但当我试图通过OAuth进程获取私有播放列表时,我无法获取私有播放列表ID,只有公共播放列表显示。即使我尝试了api explorer,我也能看到下面唯一非私有的公共播放列表是我的代码,请帮助我 Credential credential = getCredentials(); youTube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, cred
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());
}
}
Credential-Credential=getCredentials();
youTube=new youTube.Builder(HTTP_传输,JSON_工厂,凭证).setApplicationName(“播放列表Web应用”).build();
字符串channelID=getDefaultChannelId();
YouTube.Search.List Search=YouTube.Search().List(“id,snippet”);
search.setChannelId(channelID);
search.setType(“播放列表”);
search.setFields(“项(id/playlid、种类、片段(标题))”;
search.setMaxResults((长)10);
SearchListResponse searchResponse=search.execute();
List searchResultList=searchResponse.getItems();
if(searchResultList!=null){
迭代器迭代器SearchResults=searchResultList.Iterator();
如果(!iteratorSearchResults.hasNext()){
System.out.println(“您的查询没有任何结果。”);
}
while(iteratorSearchResults.hasNext()){
SearchResult playlist=iteratorSearchResults.next();
ResourceId rId=playlist.getId();
System.out.println(“Playlist Id:+Playlist.getId().getPlaylistId());
System.out.println(“标题:+playlist.getSnippet().getTitle());
}
}
我遵循OAuth流程,但无法获得自己的私人播放列表。是的,现在我可以获得我频道的私人播放列表。 而不是
YouTube.Search.List Search=YouTube.Search().List(“id,snippet”)代码>和设置search.setType(“播放列表”)代码>最好选择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());
}
}
Credential-Credential=getCredentials();
youTube=new youTube.Builder(HTTP_传输,JSON_工厂,凭证).setApplicationName(“播放列表Web应用”).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((长)10);
playListResponse playListResponse=searchList.execute();
List playlists=playListResponse.getItems();
如果(播放列表!=null){
迭代器iteratorPlaylistResults=播放列表。迭代器();
如果(!iteratorPlaylistResults.hasNext()){
System.out.println(“您的查询没有任何结果。”);
}
而(iteratorPlaylistResults.hasNext()){
Playlist Playlist=iteratorPlaylistResults.next();
System.out.println(“playlistid:+Playlist.getId());
System.out.println(“标题:+playlist.getSnippet().getTitle());
}
}
有关YouTube的更多服务,请访问以下网站