【问题标题】:The request uses the <code>mine</code> parameter but is not properly authorized请求使用 <code>mine</code> 参数但未正确授权
【发布时间】:2019-02-19 05:15:54
【问题描述】:

我正在尝试使用我的参数调用 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);

【问题讨论】:

    标签: php youtube-api youtube-data-api


    【解决方案1】:

    在访问我的 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 密钥进行身份验证。

    【讨论】:

    • OP 的代码确实进行了身份验证:$client-&gt;authorize()。反问:您是否曾经通过Google APIs Client Library for PHP 访问过 YouTube Data API(或任何其他 Google API)?
    猜你喜欢
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-06
    • 2021-12-04
    • 2020-12-31
    • 1970-01-01
    相关资源
    最近更新 更多