我想使用youtube:s API v2将视频添加到现有播放列表。
我可以添加新的播放列表和视频我可以修改播放列表说明和标题。但是当我尝试使用相同的代码块将视频添加到现有播放列表时,没有任何反应。我没有收到错误消息。
这是我的代码:
public static Feed<Playlist> GetAllPlayLists(Video video)
{
var request = DoYouTubeRequest();
Feed<Playlist> userPlaylists = request.GetPlaylistsFeed(Constants.YouTubeCompany);
foreach (Playlist p in userPlaylists.Entries)
{
if (p.Title == "TEST")
{
AddVideoToPlayList(video, p); // Nothings happens
p.Summary = "updated summary " + DateTime.Now; // This works
request.Update(p);
}
}
return null;
}
private static YouTubeRequest DoYouTubeRequest()
{
YouTubeRequestSettings settings = new YouTubeRequestSettings("Test", Constants.YouTubeDeveloperKey, Constants.YoutubeUserName, Constants.YoutubePassword);
YouTubeRequest request = new YouTubeRequest(settings);
return request;
}
public static void AddVideoToPlayList(Video video, Playlist playlist)
{
YouTubeRequest request = DoYouTubeRequest();
PlayListMember pm = new PlayListMember();
pm.VideoId = video.VideoId;
try
{
request.AddToPlaylist(playlist, pm);
}
catch (Exception ex)
{
throw new Exception("Exception in function AddVideoToPlayList:" + ex.Message);
}
}
public static Playlist CreatePlaylist(string title, string summary, Video v)
{
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(summary))
{
throw new ArgumentNullException("title and/or summary is null or empty");
}
var request = DoYouTubeRequest();
Playlist pl = new Playlist();
pl.Title = title;
pl.Summary = summary;
Playlist createdPlaylist = request.Insert(new Uri("https://gdata.youtube.com/feeds/api/users/default/playlists"), pl);
AddVideoToPlayList(v, createdPlaylist);
return null;
}