c# - 如何自动管理 YouTube 帐户的播放列表

标签 c# youtube google-api-client youtube-data-api

我需要什么

I'm working on a C# app that scans Facebook messages for youtube links and adds each new video to an existing playlist. If the playlist doesn't exist yet, it needs to be created.

我有什么

我有这段代码可以创建一个新的播放列表:

// 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.
}

问题

  1. How do I check if a playlist already exists?

  2. How do I check if a videa was already added?

最佳答案

您可以使用 YouTube Data API v3访问数据:

  1. Playlists: list - 将允许您列出用户的所有播放列表
  2. PlaylistItems: list - 将允许您列出播放列表中的项目

关于c# - 如何自动管理 YouTube 帐户的播放列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39540770/

相关文章:

c# - 单击 HTML 按钮(不是提交或表单的发布按钮)调用 Controller 的特定操作 Asp.net MVC

c# - 我们是否必须在应用程序级别处理蓝牙 LE 通信中的 MTU?

c# - 以编程方式将证书添加到受信任的发布者

html - 如何在 <iframe> 之上叠加 <textarea>?

youtube - 如何在我的应用程序中添加 YouTube VrView 按钮,并仅在应用程序中显示来自播放列表的 360 度视频?

python-2.7 - httplib2.ServerNotFoundError : Unable to find the server at www. googleapis.com

c# - 我应该在 linq 搜索中使用字典还是列表?

android - URL链接Cardboard和youtube Android

php - 如何从访问 token google api php获取用户电子邮件

android - 如果没有更新 Google Play 服务,如何处理 Google API 客户端