1
votes

I'm trying to delete videos via the YouTube API and getting a 401 status code telling me that login is required:

YouTube delete exception: Client error: `DELETE https://www.googleapis.com/youtube/v3/videos?id=qHwE11JqiW8&onBehalfOfContentOwner=SNIP&prettyPrint=1` resulted in a `401 Unauthorized` response: { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", (truncated...)

Here's the code creating my Google client object:

    $google_client = new Google_Client();
    $google_client->setHttpClient($this->httpClient);
    $google_client->addScope([\Google_Service_YouTube::YOUTUBE, \Google_Service_YouTubePartner::YOUTUBEPARTNER]);
    // This ensures the token is refreshed automatically for the life of the
    // client.
    $google_client->setAccessType('offline');
    if (!empty($google_auth_config['client_id_json'])) {
      $decoder = new JsonDecode(TRUE);
      $google_client->setAuthConfig($decoder->decode($google_auth_config['client_id_json'], 'json'));
    }
    if (!empty($google_auth_config['refresh_token'])) {
      $google_client->fetchAccessTokenWithRefreshToken($google_auth_config['refresh_token']);

    }
    if (!empty($google_auth_config['redirect_uri'])) {
      $google_client->setRedirectUri($google_auth_config['redirect_uri']);
    }

    return $google_client;

var_dump($google_client) has this, which sure looks like it's got the auth pieces it needs (access_token and refresh_token). ["token":"Google_Client":private]=> array(6) { ["access_token"]=> string(131) "a big long hash looking thing generated by Google Client fetchAccessTokenWithRefreshToken()" ["expires_in"]=> int(3600) ["scope"]=> string(86) "https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube" ["token_type"]=> string(6) "Bearer" ["created"]=> int(1566992903) ["refresh_token"]=> string(45) "token generated by Google Oauth2" }

1
PS -- $queryParams does include the correct onBehalfOfContentOwner value. - Sunset Bill
You should read the full response not just the status code it will give you an idea of whats going on. - DaImTo
I added another statement to print out the message body. There isn't one, so no help there, either. - Sunset Bill
id10t error here. All that code is doing for response is creating a new one, it's not getting the result of the service call. - Sunset Bill

1 Answers

-1
votes

If you check the documentation for that method it tells you what the response means

video.delete

enter image description here