使用YouTube API v3更新YouTube播放列表状态,标题和说明

时间:2015-04-17 06:19:53

标签: java youtube youtube-data-api

我正在尝试使用java中的YouTube API v3更新播放列表的status(public, private, unlisted)

YouTube.Playlists.Update playlistUpdateCommand =  youTube.playlists().update(arg0, arg1);

arg0是一个字符串 arg1是一个播放列表

更新方法中的参数arg0应该是什么。以及我如何设置播放列表的标题,描述和状态。

请帮帮我

1 个答案:

答案 0 :(得分:0)

我可以管理更新播放列表的状态。

要更新播放列表的状态,标题和说明,我们首先需要OAuth,您必须是播放列表的所有者。稍后我们需要通过设置状态,标题和描述(您希望更改)来构建播放列表。

标题和说明通过PlaylistSnippet设置,状态由PlaylistStatus设置。现在将这两个设置为播放列表,如下面的代码所示

    Credential credential = new GoogleCredential.Builder()
            .setTransport(new NetHttpTransport())
            .setJsonFactory(new JacksonFactory())
            .setClientSecrets(CLIENT_ID, CLIENT_SECRET)
            .build();
    credential.setRefreshToken(getAccessToken());


    youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
        .setApplicationName("API Project")
        .build();


    PlaylistSnippet playlistSnippet = new PlaylistSnippet();
        playlistSnippet.setTitle("My Title of the playlist  " + Calendar.getInstance().getTime());
        playlistSnippet.setDescription("A private playlist created with the YouTube API v3");
        PlaylistStatus playlistStatus = new PlaylistStatus();
        playlistStatus.setPrivacyStatus("private"); //private, public, unlisted

    Playlist youTubePlaylist = new Playlist();
        youTubePlaylist.setSnippet(playlistSnippet); 
        youTubePlaylist.setStatus(playlistStatus);
        youTubePlaylist.setId("PLEv-m2yWNXmS-xOK5GCQ6i6KMFuQcjOlo");  //playlist id starts with PL

    // Now playlist is ready now create update command and execute it

    YouTube.Playlists.Update playlistUpdateCommand = youTube.playlists().update("snippet,status", youTubePlaylist);

    Playlist playlistUpdated = playlistUpdateCommand.execute();


    System.out.println("New Playlist name: " + playlistUpdated.getSnippet().getTitle());
        System.out.println(" - Privacy: " + playlistUpdated.getStatus().getPrivacyStatus());
        System.out.println(" - Description: " + playlistUpdated.getSnippet().getDescription());