【问题标题】:YouTube Data API v.3.0 Unable to Add/Delete Video from Playlist - InsufficientPermissions ExceptionYouTube Data API v.3.0 无法从播放列表添加/删除视频 - InsufficientPermissions 异常
【发布时间】:2014-06-23 10:14:33
【问题描述】:

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

认证方式:

 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 权限不足 [403] 错误 [ Message[Insufficient Permissions] Location[-] Reason[insufficientPermissions] Domain[global] ]

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

【问题讨论】:

    标签: c# android youtube


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-11
      • 2015-12-31
      • 2017-06-25
      • 2018-04-01
      • 2014-02-07
      • 1970-01-01
      • 2014-02-12
      • 1970-01-01
      相关资源
      最近更新 更多