Php 请求评论时,Youtube API返回的权限不足

Php 请求评论时,Youtube API返回的权限不足,php,api,youtube-api,authorization,Php,Api,Youtube Api,Authorization,我正在尝试检索用户视频的评论线程,但遇到403权限不足错误 开发者控制台中的oAuth客户端启用了Youtube数据v3 API,并且在生成令牌时设置了Youtube作用域 这是我用来在oauth流中授权应用程序的客户端。我尝试了youtube作用域和youtube.readonly作用域,但都没有公开评论线程 $client = new Google_Client(); $client->setClientId($auth_config['client_id']); $client-&g

我正在尝试检索用户视频的评论线程,但遇到403权限不足错误

开发者控制台中的oAuth客户端启用了Youtube数据v3 API,并且在生成令牌时设置了Youtube作用域

这是我用来在oauth流中授权应用程序的客户端。我尝试了youtube作用域和youtube.readonly作用域,但都没有公开评论线程

$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]);

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

我找到了解决方案。使用强制ssl作用域修复了它

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

不知道为什么ssl作用域在普通youtube作用域不起作用时起作用,特别是对于仅列出注释的情况。

对于JavaScript开发人员

var OAUTH2_SCOPES = [
  'https://www.googleapis.com/auth/youtube',
  'https://www.googleapis.com/auth/youtube.force-ssl'
];
要从YouTube API检索评论,请添加 将其放入OAUTH2_作用域数组中