1

i dont seem to get the refresh token when i call the access token? Here is the code:

$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes('https://www.googleapis.com/auth/youtube');
$redirect = filter_var(URL,
FILTER_SANITIZE_URL);
$client->setRedirectUri($redirect);
$client->setApprovalPrompt("force"); 
$client->setState('offline');

var_dump($client->getAccessToken());

And this is what i get from it:

string(163) "{"access_token":"","token_type":"Bearer","expires_in":3599,"created":1111111111}"

Why dont i get the refresh token?

1 Answers1

0

One thing you should be careful about: a refresh token is returned (in addition to the access token) only when the user gives consent explicitly for the requested scopes. Basically, when the approval page is shown. All subsequent flows will only return an access token.

You are missing

$client->setApprovalPrompt("force"); 

How to get offline token and refresh token and auto-refresh access to Google API

Community
  • 1
  • 1
greg_diesel
  • 2,955
  • 1
  • 15
  • 24
  • Thanks for the help. However this does not solve the issue. I still only get the access token: string(163) " {"access_token":"ya29.FgFml_QHQMORS0GqtL7kCZ3PO-gqm4fJOCj1hC5IYdJGptbGKtIBwrdnsWNauqFPIsXOgj1iuy3CQw","token_type":"Bearer","expires_in":3600,"created":1423558200}" – Pontus Johansson Feb 10 '15 at 08:53
  • Partly this was the error. Thanks alot for the help =) – Pontus Johansson Feb 10 '15 at 13:03