Google API update label not sent

I am trying to use the YouTube YouTube data API with PHP based on the Google documentation here: https://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2#OAuth2_Refreshing_a_Token . My problem occurs when authenticating with OAuth. I use the following authorization URL, which is identical to what the docs say, except for my uri redirection and application key, obviously.

$this->authorizationUrl = 'https://accounts.google.com/o/oauth2/auth?'; $this->authorizationUrl .= 'client_id=' . $this->applicationKey . '&'; $this->authorizationUrl .= 'redirect_uri=' . $this->redirect_uri . '/account.php?action=youtube_oauth&'; $this->authorizationUrl .= 'scope=https://gdata.youtube.com&'; $this->authorizationUrl .= 'response_type=code&'; $this->authorizationUrl .= 'access_type=offline'; 

Then, as the docs say, I find the following:

 $curl_options = Array( CURLOPT_POSTFIELDS => Array( 'code' => $code, 'client_id' => $this->applicationKey, 'client_secret' => $this->applicationSecret, 'redirect_uri' => $this->redirect_uri . '/account.php?action=youtube_oauth', 'grant_type' => 'authorization_code' ), CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => 'https://accounts.google.com/o/oauth2/token' ); 

However, my answer never gives me a refresh_token, as in their documentation. I just get the other three response elements.

Some questions like this one: Get the refresh google api token , said they use assert_prompt = force, but this does not work and the goal completely wins is to have access_type = missing.

Any ideas as to why I am getting a valid answer with 3 of 4 response elements?

+7
source share
2 answers

From offline access to OAuth2.0 documents:

When your application receives an update token, it is important to keep this update token for future use. If your application loses an update token, it will have to re-request the user to obtain consent before receiving another update token. If you need to re-request the user for consent, enter the approval_prompt parameter in the request for the authorization code and set the value to force .

So, if you have already granted access, subsequent requests for grant_type from authorization_code will not return refresh_token , even if access_type was set offline in the request line on the consent page.

As stated in the quote above, in order to get a new refresh_token after receiving it, you will need to send your user back through an invitation, which you can do by setting approval_prompt to force .

Greetings

PS This change was announced in the message.

+28
source

You can try google oauth2 playground (https://code.google.com/oauthplayground/) and see what differences exist between your settings and there.

+2
source

All Articles