谷歌API -刷新令牌



我试图在他过期后获得一个新的access_token。我已经在银行中保存了我收到的第一个客户端访问返回的信息:

{"access_token": "TOKEN", "refresh_token": "TOKEN", "token_type", "Bearer", "expires_in": 3600, "created ": 1320790426}

令牌过期后,我需要申请一个新的,我这样做:

$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->setAccessType('offline');
$token['access_token']  = $db->dados[0]['use_access_token'];
$token['refresh_token'] = $db->dados[0]['use_refresh_token'];
$token['token_type']    = $db->dados[0]['use_token_type'];
$token['expires_in']    = $db->dados[0]['use_expires_in'];
$token['created']       = $db->dados[0]['use_created'];
$client->setAccessToken(json_encode($token));
if ($client->isAccessTokenExpired()) {
    echo "Expired !";
    $client->refreshToken($client->getRefreshToken());
    //$accessToken = $client->authenticate($authCode);
} else {
    ...
}

问题是它总是返回这个错误:刷新OAuth2令牌错误,消息:

{"error": "invalid_grant"}

    $client->refreshToken($refreshToken);
    $newtoken=$client->getAccessToken();
    echo $newtoken."</br>";

相关内容

  • 没有找到相关文章

最新更新