【问题标题】:How to get private playlist ids through YouTube API V3?如何通过 YouTube API V3 获取私有播放列表 ID?
【发布时间】:2023-04-03 22:36:02
【问题描述】:

我有一个 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 流程,但无法获得自己的私人播放列表。

【问题讨论】:

    标签: java api youtube youtube-api youtube-data-api


    【解决方案1】:

    是的,现在我可以获得我频道的私人播放列表。 而不是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/

    【讨论】:

      猜你喜欢
      • 2015-01-06
      • 2015-02-26
      • 2015-07-05
      • 2017-11-01
      • 2015-10-26
      • 2015-08-20
      • 2022-01-15
      • 2016-11-21
      • 2015-10-18
      相关资源
      最近更新 更多