2016-05-07 5 views
1

access_tokenは私が唯一の最初の試み例外:必要なオプションが渡されない:あなたがのOAuth2を使用している場合

Fatal error: Uncaught exception 'Exception' with message ' in ..../application/libraries/OAuth2/Token/Access.php on line 44 
Exception: Required option not passed: access_token in ..../application/libraries/OAuth2/Token/Access.php on line 44 

enter image description here

+0

おそらくコードの例を挙げることができますか? [ここ](https://developers.google.com/identity/protocols/OAuth2WebServer#handlingresponse)あなたのアプリケーションにaccesstokenを取得する方法の詳細を見つけることができます –

答えて

0

でCodeIgniterの中にグーグルでログインしようとしているときに、このエラーを取得しています、後藤ライブラリ/のOAuth2 /provider.phpそのスイッチのケースでは、アクセスと呼ばれる機能があります:POST、以下に示したことを行います。

+0

ライブラリ/ oauth2/provider.phpを見ることなく、いずれか182行ですか? '' failonerror '=> false'のものは?あなたの投稿を編集して、右の行にコメントを追加してください。コードの新しいリリースでは変更できるため、行番号だけでは適切な参照ができません。ありがとうございました! –

2

コーディング

 case 'POST': 

      $ci = get_instance(); 

      /*$ci->load->spark('curl/1.2.1'); 

      $ci->curl 
       ->create($url) 
       ->post($params, array('failonerror' => false)); 

      $response = $ci->curl->execute();*/ 

幸せはあなたのaccess.phpのファイルを変更し、方法を__construct変更しよう。

public function __construct(array $options = null) 
{ 
    echo "<pre>"; 
    $new_options = array(); 
    foreach($options as $key => $value) 
    { 
     $new_options = json_decode($key,true); 
    } 

    if (! isset($new_options['access_token'])) 
    { 
     throw new Exception('Required option not passed: access_token'.PHP_EOL.print_r($new_options, true)); 
    } 

    // if (! isset($options['expires_in']) and ! isset($options['expires'])) 
    // { 
    // throw new Exception('We do not know when this access_token will expire'); 
    // } 


    $this->access_token = $new_options['access_token']; 

    // Some providers (not many) give the uid here, so lets take it 
    isset($new_options['uid']) and $this->uid = $new_options['uid']; 

    //Vkontakte uses user_id instead of uid 
    isset($new_options['user_id']) and $this->uid = $new_options['user_id']; 

    //Mailru uses x_mailru_vid instead of uid 
    isset($new_options['x_mailru_vid']) and $this->uid = $new_options['x_mailru_vid']; 

    // We need to know when the token expires, add num. seconds to current time 
    isset($new_options['expires_in']) and $this->expires = time() + ((int) $new_options['expires_in']); 

    // Facebook is just being a spec ignoring jerk 
    isset($new_options['expires']) and $this->expires = time() + ((int) $new_options['expires']); 

    // Grab a refresh token so we can update access tokens when they expires 
    isset($new_options['refresh_token']) and $this->refresh_token = $new_options['refresh_token']; 
} 
+0

このソリューションはfacebookでうまく動作しますが、Googleログインにエラーが発生します –

関連する問題