6

使用 Laravel Socailite 连接到 Google API,我可以恢复连接,但是此访问不会返回刷新令牌,因此我的连接超时。

$scopes = [
            'https://www.googleapis.com/auth/webmasters',
            'https://www.googleapis.com/auth/webmasters.readonly',
            'https://www.googleapis.com/auth/analytics.readonly',
            'https://www.googleapis.com/auth/userinfo.profile',
            'https://www.googleapis.com/auth/userinfo.email',
          ];    
$parameters = ['access_type' => 'offline'];
return Socialite::driver('google')->scopes($scopes)->with($parameters)->redirect();

如何取回刷新令牌?

4

1 回答 1

8

当您将用户重定向到 Google 时,请在重定向时使用 with() 方法将 access_type 设置为离线,如下所示:

return Socialite::driver('google')
    ->scopes() // For any extra scopes you need, see https://developers.google.com/identity/protocols/googlescopes for a full list; alternatively use constants shipped with Google's PHP Client Library
    ->with(["access_type" => "offline", "prompt" => "consent select_account"])
    ->redirect();
于 2017-05-29T14:47:32.483 回答