php – 使用Laravel Socialite获取Google刷新令牌
发布时间:2020-12-14 19:42:56 所属栏目:大数据 来源:网络整理
导读:使用Laravel Socailite连接到Google API并且我正在恢复连接,但是此访问不会返回刷新令牌,因此我的连接超时. $scopes = [ 'https://www.googleapis.com/auth/webmasters','https://www.googleapis.com/auth/webmasters.readonly','https://www.googleapis.com
使用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(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |