php - 请求使用mine
参数但未正确授权
问题描述
我正在尝试使用我的参数调用 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);
解决方案
在访问我的 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
mine
如果您设置为更精确的参数,则true
必须通过 OAuth2 而不是您的 API 密钥进行身份验证。
推荐阅读
- odoo - 考勤模块 Odoo 中的地理位置
- python - 您如何按 Boto 中的 CreationDate 字符串对 AMI 进行排序?
- google-workspace - 关于计费的 Google API
- r - 如何防止 R 中的 gamm4 在我的 GAMM 中删除列/系数?
- react-redux - 如何在下面的代码中添加字体图标?
- optimization - scipys linprog 求解器没有可用的复杂性信息?
- hyperlink - 使用 mapbox 在弹出窗口中添加链接
- css - 是否可以让 flex div 坐在有空间的地方?
- database - HBase 在大 o-notation 中通过 rowkey 获取行的性能
- c# - 修复 .NET Core App 3.1 开源依赖项漏洞