使用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();
如何获取刷新令牌?
解决方法
当您将用户重定向到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();