doufen3838 2015-09-28 20:38
浏览 224

Google API - 刷新令牌

I'm trying to get a new access_token after he expired. I already keep in the bank the information I receive in return the first client access:

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

After that token expires I need to apply for a new one, I am doing this way:

$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 {
    ...
}

The problem is that always returns this error: Error refreshing the OAuth2 token, message:

{ "error" : "invalid_grant" }

  • 写回答

1条回答 默认 最新

  • douwen4401 2015-09-28 20:50
    关注
        $client->refreshToken($refreshToken);
        $newtoken=$client->getAccessToken();
        echo $newtoken."</br>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器