Google API - 刷新令牌

时间:2015-09-28 20:38:09

标签: php api google-api token

我试图在他过期后获得一个新的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”}

1 个答案:

答案 0 :(得分:0)

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