例外:未通过必需选项:access_token
Posted
技术标签:
【中文标题】例外:未通过必需选项:access_token【英文标题】:Exception: Required option not passed: access_token 【发布时间】:2016-09-02 11:24:37 【问题描述】:我在第一次尝试在 Codeigniter 中使用 Google 登录时遇到此错误
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
【问题讨论】:
也许您可以举一个代码示例? Here您可以找到更多关于如何在您的应用中获取访问令牌的信息 【参考方案1】:尝试更改您的 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'];
【讨论】:
此解决方案适用于 facebook,但 google 登录出错【参考方案2】:如果您使用的是 oauth2,则转到 library/oauth2/provider.php 有一个名为 access 的函数,在该开关情况下: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();*/
愉快的编码
【讨论】:
没有看到libraries/oauth2/provider.php,第182行是哪一个?带有'failonerror' => false
的那个?请edit您的帖子并在右行添加评论。单独的行号不是一个很好的参考,因为随着代码的更新版本,它们可能会改变。谢谢!【参考方案3】:
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'];
【讨论】:
以上是关于例外:未通过必需选项:access_token的主要内容,如果未能解决你的问题,请参考以下文章
为啥我会收到 OleDbException:“没有为一个或多个必需参数提供值。”例外?
例外:render() 缺少 1 个必需的位置参数:'template_name'。为啥我得到这个异常?以前没有遇到过这个
Rails 5 simple_form 将单选按钮标记为必需,如果未填写则阻止提交表单