我需要什么
我正在使用C#应用程序扫描Facebook消息中的youtube链接 并将每个新视频添加到现有播放列表中。如果播放列表不存在 然而,它需要被创造。
我有什么
我有这个代码可以创建一个新的播放列表:
// Create a new, private playlist in the authorized user's channel.
var newPlaylist = new Playlist();
newPlaylist.Snippet = new PlaylistSnippet();
newPlaylist.Snippet.Title = "Test Playlist";
newPlaylist.Snippet.Description = "A playlist created with the YouTube API v3";
newPlaylist.Status = new PlaylistStatus();
newPlaylist.Status.PrivacyStatus = "public";
newPlaylist = await youtubeService.Playlists.Insert(newPlaylist, "snippet,status").ExecuteAsync();
但是由于它的插入,它将始终在多次运行中创建同一请求的播放列表的新实例。如果播放列表已存在,则应该更新。
这是添加新视频的代码,也是插入:
try
{
// Add a video to the newly created playlist.
var newPlaylistItem = new PlaylistItem();
newPlaylistItem.Snippet = new PlaylistItemSnippet();
newPlaylistItem.Snippet.PlaylistId = "PLMl3RyOwPdGlcrBTNYiu1XiNNgqYx6mx8";
//newPlaylistItem.Snippet.PlaylistId = newPlaylist.Id;
newPlaylistItem.Snippet.ResourceId = new ResourceId();
newPlaylistItem.Snippet.ResourceId.Kind = "youtube#video";
newPlaylistItem.Snippet.ResourceId.VideoId = videoId;
newPlaylistItem = await youtubeService.PlaylistItems.Insert(newPlaylistItem, "snippet").ExecuteAsync();
}
catch (Exception ex)
{
// Do some logging.
// Likely doesn't exist anymore, ignore.
}
问题
如何检查播放列表是否已存在?
- 醇>
如何检查是否已添加视频?
答案 0 :(得分:3)
您可以使用YouTube Data API v3访问数据: