例外:未传递必需选项:access_token

时间:2016-05-07 12:18:51

标签: php codeigniter oauth-2.0 google-signin

我尝试仅在首次尝试时使用Google登录Codeigniter时收到此错误

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

3 个答案:

答案 0 :(得分:2)

尝试更改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'];
}

答案 1 :(得分:0)

如果你正在使用oauth2,那么goto libraries / oauth2 / provider.php就有一个名为access的函数,在那个switch case:POST中,按照我在下面显示的那样做。

        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();*/

快乐编码

答案 2 :(得分:0)

public function __construct(array $options = null)
{
    $new_options = array();
    foreach($options as  $key => $value)
    {
         $new_options = json_decode($key,true);
    }
    if($new_options==null || $new_options=="")
    {
        $new_options=$options;
    }
    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'];
}