2

I use this script: https://developers.google.com/youtube/v3/code_samples/php#resumable_uploads to upload videos to youtube. Everything works fine, but next day I have error:

An client error occurred: The OAuth 2.0 access token has expired, and a refresh token is not available. Refresh tokens are not returned for responses that were auto-approved.

I looked at some tips on how to fix this but I did not succeed. I am new to programming. Please help me fix this error.

1 Answer 1

2

You need to set the access type to offline which allows you to refresh the access token so you can authenticate the app without the user having to give authorization again.

Check the docs.

I can't test this now, but try the following. This isn't ideal though, you should be persisting the token somewhere.

// After "$client->setRedirectUri($redirect);" add:
$client->setAccessType('offline');


// After "$client->setAccessToken($_SESSION['token']);" add:
if ($client->isAccessTokenExpired()) {
    $currentTokenData = json_decode($_SESSION['token']);
    if (isset($currentTokenData->refresh_token)) {
        $client->refreshToken($currentTokenData->refresh_token);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Please help me. What I must edit in this script developers.google.com/youtube/v3/code_samples/… ??? Where I can get $refresh_token

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.