【问题标题】:Youtube API returning Insufficient Permission when requesting comments请求评论时 Youtube API 返回 Insufficient Permission
【发布时间】:2015-07-10 19:47:40
【问题描述】:

我正在尝试检索用户视频的评论线程,但收到 403 Insufficient Permission 错误。

我在开发者控制台中的 oAuth 客户端启用了 Youtube Data v3 API,并且我在生成令牌时设置了 youtube 范围。

这是我用来在 oauth 流程中授权应用程序的客户端。我已经尝试了 youtube 范围和 youtube.readonly 范围,并且都没有公开 commenThreads。

$client = new Google_Client();
$client->setClientId($auth_config['client_id']);
$client->setClientSecret($auth_config['client_secret']);
$client->setRedirectUri($auth_config['redirect_uri']));
$client->addScope(Google_Service_YouTube::YOUTUBE);
$client->setAccessType('offline');

在我的应用程序的其他地方,我使用如下令牌。

$client = new Google_Client();
$client->setAccessToken($access_token);
$youtube = new Google_Service_YouTube($client);
$comments = $youtube->commentThreads->listCommentThreads('snippet', [ 'videoId' => $videoId]);

我可以查看用户的视频,据我所知,我也应该有权查看 cmets。我错过了什么?我的代码几乎与 PHP 客户端库示例相同。

【问题讨论】:

    标签: php api youtube-api authorization


    【解决方案1】:

    我找到了解决方案。使用 force-ssl 范围修复它。

    $client->addScope(Google_Service_YouTube::YOUTUBE_FORCE_SSL);
    

    不知道为什么 ssl 范围在普通 youtube 范围不起作用时起作用,尤其是对于仅列出 cmets。

    【讨论】:

      【解决方案2】:

      对于 JavaScript 开发人员

      var OAUTH2_SCOPES = [
        'https://www.googleapis.com/auth/youtube',
        'https://www.googleapis.com/auth/youtube.force-ssl'
      ];
      

      要从 YouTube API 中检索 cmets,请添加 https://www.googleapis.com/auth/youtube.force-ssl 这进入 OAUTH2_SCOPES 数组

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-28
        • 2015-08-09
        • 2011-12-10
        • 2016-11-07
        • 2013-10-25
        • 1970-01-01
        • 2013-10-15
        • 1970-01-01
        相关资源
        最近更新 更多