c# - YouTube 数据 API v.3.0 无法从播放列表添加/删除视频 - InsufficientPermissions 异常

标签 c# android youtube

我一整天都在尝试将视频删除/添加到我的 YouTube 播放列表中。我使用的是 YouTube 数据 API v.3.0。对于.NET C#。 我已经在 Google 开发者控制台中创建了一个项目并获取了我的客户端 secret JSON 文件。另外,我用于获取列表项的代码工作正常,这意味着只有 PUT 操作未按预期工作。我使用了与 Google 开发人员站点代码示例中几乎相同的代码。

认证方式:

 private async Task<YouTubeService> GetYouTubeService(string userEmail)
    {
        UserCredential credential;
        using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new[]
                { 
                    YouTubeService.Scope.Youtube,
                    YouTubeService.Scope.Youtubepartner,
                    YouTubeService.Scope.YoutubeUpload,
                    YouTubeService.Scope.YoutubepartnerChannelAudit, 
                    YouTubeService.Scope.YoutubeReadonly 
                },
                userEmail,
                CancellationToken.None,
                new FileDataStore(this.GetType().ToString()));
        }

        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = this.GetType().ToString()
        });

        return youtubeService;
    }

将视频添加到播放列表代码:

  private async Task AddSongToPlaylistAsync(string userEmail, string songId, string playlistId)
    {
        var youtubeService = await this.GetYouTubeService(userEmail);
        var newPlaylistItem = new PlaylistItem();
        newPlaylistItem.Snippet = new PlaylistItemSnippet();
        newPlaylistItem.Snippet.PlaylistId = playlistId;
        newPlaylistItem.Snippet.ResourceId = new ResourceId();
        newPlaylistItem.Snippet.ResourceId.Kind = "youtube#video";
        newPlaylistItem.Snippet.ResourceId.VideoId = songId;
        newPlaylistItem = await youtubeService.PlaylistItems.Insert(newPlaylistItem, "snippet").ExecuteAsync();
    }

这是我尝试将新视频添加到指定播放列表时收到的消息:

Google.Apis.Requests.RequestError Insufficient Permission [403] Errors [ Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global] ]

我真的很感激任何可用的帮助,因为我没有找到任何有用的谷歌搜索。 先感谢您!

最佳答案

我遇到了同样的问题,但如果有人在将视频添加到播放列表时遇到低效权限问题,您将需要拥有 YouTubeService.Scope.Youtube (看起来您已经有)。

var scopes = new[]
{
    YouTubeService.Scope.Youtube
};

但是,如果您在授予权限后添加了范围,则需要通过转到此页面 manage permissions 来撤销客户端。 。您必须寻找您的特定客户。完成此操作后,您可以重新运行您的应用并再次请求权限。

另一个选择是再次创建新的 clientId 和 clientSecret 并确保您拥有正确的范围。我希望这会有所帮助。

关于c# - YouTube 数据 API v.3.0 无法从播放列表添加/删除视频 - InsufficientPermissions 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23500797/

相关文章:

c# - 从内存集合中快速自动完成 (.NET)

c# - 为 RichTextBox 字符串的不同部分着色

c# - OWIN MVC - 多个 LoginProvider,当前 LoginProvider

android - Sony Xperia Tablet Z 上的 CSS 伪元素渲染问题

node.js - 当第一首歌曲流完成时如何修复 "Stream is not generating quickly enough"错误?

C# 多项选择测试

android - 错误膨胀类 com.facebook.drawee.view.SimpleDraweeView

java - 对 token 感到困惑

list - 是否可以从文本文件中制作YouTube列表?

ios - 上传视频并分享链接 - API?