Reputation: 6348
I'm trying to retrieve comment threads for a users video but I'm getting a 403 Insufficient Permission error.
My oAuth client in the developers console has the Youtube Data v3 API enabled and I set the youtube scope when the token is generated.
Here is the client I use to authorize the app in the oauth flow. I've tried both the youtube scope and the youtube.readonly scope and neither expose 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');
Elsewhere in my app I use the token like below.
$client = new Google_Client();
$client->setAccessToken($access_token);
$youtube = new Google_Service_YouTube($client);
$comments = $youtube->commentThreads->listCommentThreads('snippet', [ 'videoId' => $videoId]);
I can view the users videos and as far as I can tell I should have permission to view comments too. What am I missing? My code is almost identical to the PHP client library example.
Upvotes: 1
Views: 1404
Reputation: 3700
For JavaScript developers
var OAUTH2_SCOPES = [
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/youtube.force-ssl'
];
to retrieve comments from the YouTube API add https://www.googleapis.com/auth/youtube.force-ssl this into OAUTH2_SCOPES array
Upvotes: 1
Reputation: 6348
I found the solution. Using the force-ssl scope fixed it.
$client->addScope(Google_Service_YouTube::YOUTUBE_FORCE_SSL);
Not sure why the ssl scope works when the plain youtube scope doesn't, especially for just listing comments.
Upvotes: 2