我试图用我的参数调用YouTube频道API,但我得到了下面的错误。
[
"error" => array:3 [
"errors" => array:1 [
0 => array:5 [
"domain" => "youtube.parameter"
"reason" => "authorizationRequired"
"message" => "The request uses the <code>mine</code> parameter but is not properly authorized."
"locationType" => "parameter"
"location" => "mine"
]
]
"code" => 401
"message" => "The request uses the <code>mine</code> parameter but is not properly authorized."
]
]
通过下面的代码,我调用youtube v3 api
$client = new \Google_Client();
$client->setAuthConfig(app_path('google-api.json'));
$client->setScopes([
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/youtubepartner-channel-audit',
\Google_Service_YouTube::YOUTUBE_FORCE_SSL,
]);
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/login');
$client->setAccessType('offline');
$client->setIncludeGrantedScopes(true);
$httpClient = $client->authorize();
$customerResponse = $httpClient->get('https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&mine=true&key={API_KEY}');
$customer = json_decode($customerResponse->getBody()->getContents(), true);
2条答案
按热度按时间mu0hgdu01#
在访问我的YouTube频道后,使用网页的“执行”按钮,您的请求有效:https://developers.google.com/youtube/v3/docs/channels/list?apix_params=%7B%22part%22%3A%5B%22snippet%2CcontentDetails%2Cstatistics%22%5D%2C%22mine%22%3Atrue%7D
更准确地说,如果设置为
true
,则必须通过OAuth2进行身份验证,而不是通过API密钥。oaxa6hgo2#
我也有同样的问题,在这个link中建议我们应该在youtube url的末尾添加这个参数:
access_token=[access_token]
对我很有效