playlistItemSnippet.setPlaylistId(playlistId);
playlistItemSnippet.setResourceId(resourceId);
// Create the playlistItem resource and set its snippet to the
// object created above.
PlaylistItem playlistItem = new PlaylistItem();
playlistItem.setSnippet(playlistItemSnippet);
// Call the API to add the playlist item to the specified playlist.
// In the API call, the first argument identifies the resource parts
// that the API response should contain, and the second argument is
// the playlist item being inserted.
YouTube.PlaylistItems.Insert playlistItemsInsertCommand = youtube
.playlistItems().insert("snippet,contentDetails", playlistItem);
PlaylistItem returnedPlaylistItem = playlistItemsInsertCommand
.execute();
log.debug("New PlaylistItem name: "
+ returnedPlaylistItem.getSnippet().getTitle());
log.debug(" -Video id: "
+ returnedPlaylistItem.getSnippet().getResourceId()
.getVideoId());
log.debug(" -Posted: "
+ returnedPlaylistItem.getSnippet().getPublishedAt());
log.debug(" -Channel: "
+ returnedPlaylistItem.getSnippet().getChannelId());
return returnedPlaylistItem.getId();
}