Oauth 2.0 刷新令牌问题 PHP

Oauth 2.0 issues with refresh token PHP

我在调用访问令牌时似乎没有获得刷新令牌?这是代码:

$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());

这就是我从中得到的:

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

为什么我没有得到刷新令牌?

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.

你不见了

$client->setApprovalPrompt("force"); 

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