Not receiving Google OAuth refresh token

前端 未结 14 1404
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 07:38

I want to get the access token from Google. The Google API says that to get the access token, send the code and other parameters to token generating page, and the response

14条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 08:14

    I searched a long night and this is doing the trick:

    Modified user-example.php from admin-sdk

    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');
    $authUrl = $client->createAuthUrl();
    echo "";
    

    then you get the code at the redirect url and the authenticating with the code and getting the refresh token

    $client()->authenticate($_GET['code']);
    echo $client()->getRefreshToken();
    

    You should store it now ;)

    When your accesskey times out just do

    $client->refreshToken($theRefreshTokenYouHadStored);
    

提交回复
热议问题