0

これはGoogleのログイン用の私のコントローラです。コードはGoogleレスポンスコードの後に​​動作しません。codeigniter googleで実装されているGoogleのコード "/"をコードに掛けた値の応答コードを返す

public function index(){ 
    // Include the google api php libraries 
    require_once APPPATH.'libraries/google-api-php-client/vendor/autoload.php'; 

    // Google Project API Credentials 
    $clientId = 'mentioned'; 
    $clientSecret = 'mentioned'; 
    $redirectUrl = base_url() . 'user_authentication/'; 


    // Google Client Configuration 
     $gClient = new Google_Client(); 
     $gClient->addScope('email'); 
     $gClient->setApplicationName('REDBUD HOTELS'); 
     $gClient->setClientId($clientId); 
     $gClient->setClientSecret($clientSecret); 
     $gClient->setRedirectUri($redirectUrl); 
     $google_oauthV2 = new Google_Service($gClient); 
//GOOGLE response 
     if (isset($_REQUEST['code'])) 
        { 
        $gClient->authenticate($_REQUEST['code']); 
        $this->session->set_userdata('token', $gClient->getAccessToken()); 
        header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);  

        } 
//check if $token us set 
     $token = $this->session->userdata('token'); 
     if (!empty($token)) 
      { 
      $gClient->setAccessToken($token); 
      } 

     if ($gClient->getAccessToken()) 
      { 
      $userProfile = $plus->userinfo->get(); 
      // Preparing data for database insertion 
      $userData['oauth_provider'] = 'google'; 
      $userData['oauth_uid'] = $userProfile['id']; 
      $userData['first_name'] = $userProfile['given_name']; 
      $userData['last_name'] = $userProfile['family_name']; 
      $userData['email'] = $userProfile['email']; 
      $userData['gender'] = $userProfile['gender']; 
      $userData['locale'] = $userProfile['locale']; 
      $userData['profile_url'] = $userProfile['link']; 
      $userData['picture_url'] = $userProfile['picture']; 
      // Insert or update user data 
      $userID = $this->user->checkUser($userData); 
      if(!empty($userID)) 
      { 
       $data['userData'] = $userData; 
       $this->session->set_userdata('userData',$userData); 
      } else 
      { 
       $data['userData'] = array(); 
      } 
     } else 
     { 
      $data['authUrl'] = $gClient->createAuthUrl(); 
     } 
     $this->load->view('user_authentication/index',$data); 
    } 

"のGoogle user_authenticationからの応答コード/?コード= 4/5wcPW5Yv6qNONOzeUz5gun4PtfuPTa6mPN9r97BDhGM番号" も良く$plus->userinfo->get() or $google_oauthV2->userinfo->get();

答えて

0

Googleの応答コードが "/"

ていない何をする必要があります教えてください

例:http://www.example.com/storage_integration/granted?code=4/oXKtlTyfmtzUBc5CjbafSpwItMz7itZMhM54VpKEbwI

の代わりに$_GETを使用できます3210

if (isset($_GET['code'])) { 
    // authenticate auth code here 
} 
+0

私はこれを試してみましたが、codeigniterのユーザーフレンドリーなURLのため、このレスポンスはGoogleから返されます –

+0

@Pawansharmaあなたは完全なエラーメッセージを投稿できますか? –

+0

私は、単に新しいGoogle_Service($ gClient)オブジェクトを置き換えるだけでgoogleのapiのアップデートだったという問題について考えすぎました。 Google_Service_Oauth2($ gClient);私の問題を解決しました。 –

0

新しいGoogle_Service($ gClient)を置き換えるだけで、 Google_Service_Oauth2($ gClient);

関連する問題