Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过谷歌登录刷新令牌的Laravel社交名流为空_Php_Laravel_Google Api_Google Oauth_Google My Business Api - Fatal编程技术网

Php 通过谷歌登录刷新令牌的Laravel社交名流为空

Php 通过谷歌登录刷新令牌的Laravel社交名流为空,php,laravel,google-api,google-oauth,google-my-business-api,Php,Laravel,Google Api,Google Oauth,Google My Business Api,我们正在使用一些google API函数,因此我们需要access\u令牌,但是refresh\u令牌似乎为空,即使我在驱动程序中添加“access\u type”=>“offline”。我错过什么了吗 这是我的密码 public function redirectToProvider(){ $scopes = array( // 'https://www.googleapis.com/auth/business.manage',

我们正在使用一些google API函数,因此我们需要
access\u令牌
,但是
refresh\u令牌
似乎为空,即使我在驱动程序中添加
“access\u type”=>“offline”
。我错过什么了吗

这是我的密码

    public function redirectToProvider(){
        $scopes = array(
            // 'https://www.googleapis.com/auth/business.manage',
            'https://www.googleapis.com/auth/plus.business.manage'
        );


        return Socialite::driver('google')->scopes($scopes)->with(['access_type'=>'offline'])->redirect();
    }
拯救部分

public function googleAuthenticate(){
        try {
            $user = Socialite::driver('google')->stateless()->user();
            $existingUser = GoogleUsers::where('email', $user->email)->first();
          
            if($existingUser){
                // dd($user);
                // $token = $user->token;
                // $refreshToken = $user->refreshToken; 
                // $expiresIn = $user->expiresIn;
                dd($user);
                return response()->json('Existing User');
             
            } else {
                $token = $user->token;
                $refreshToken = $user->refreshToken; 
                $expiresIn = $user->expiresIn;
               
                $newUser                  = new GoogleUsers;

                dd($user);

                $newUser->name            = $user->name;
                $newUser->email           = $user->email;
                $newUser->google_id       = $user->id;
                $newUser->created_at      = Carbon::now()->toDateTimeString();
                $newUser->access_token    = $user->token;
                $newUser->refresh_token   = $user->refreshToken;
                $newUser->save();
  
                // return \Redirect::route('home');
                return response()->json($token);
            }
    
            } catch (\Exception $e) {
                return response()->json($e);
        }
    }

当我执行
dd($user)
时,结果如下

Laravel\Socialite\Two\User {#317 ▼
  +token: "ya29.a0AfH6SMBcFflxhdL2RKY6k0xqIFBHqqPHaJSJPoBV2n79ozewB-9RFnBWqXJITUNyAyZlYKyOYjj0QKDDdNOREbitm13TRp4WvD2tGhCTjpcAStukUND-h59Ga0jIh27ay9JN3BQ3MyfmWwimOqryZsFWwJqy_QfVtE4He5eoVpO2mA ◀"
  +refreshToken: null
  +expiresIn: 3599
  +id: "117177930435384486747"
  +nickname: null
  +name: "Michael koh"
  +email: "user@gmail.com"
  +avatar: "https://lh6.googleusercontent.com/-Jv5Xr7SXjuE/AAAAAAAAAAI/AAAAAAAAAAA/AMZuucmNjvnp4o-Qc4Au8yMTA1XIwjw_cA/photo.jpg"
  +user: array:11 [▶]
  +"avatar_original": "https://lh6.googleusercontent.com/-Jv5Xr7SXjuE/AAAAAAAAAAI/AAAAAAAAAAA/AMZuucmNjvnp4o-Qc4Au8yMTA1XIwjw_cA/photo.jpg"
}
试试这个

 public function redirectToProvider(){
        $scopes = array(
            'https://www.googleapis.com/auth/plus.business.manage'
        );

        $parameters = ['access_type' => 'offline', "prompt" => "consent select_account"];
  
        return Socialite::driver('google')->scopes($scopes)->with($parameters)->redirect();
    }