我尝试在我的项目中使用google实现注册,但我遇到了从google接收令牌的问题。我可以重定向到google页面,在那里我需要提供电子邮件和密码,然后它重定向到提供的“重定向URI”。我也收到了代码,但我无法接收令牌。我尝试修复它,但无法找出为什么我会收到这个错误。错误生成于
$token = $google_client->fetchAccessTokenWithAuthCode($code);
这行代码。下面的和是完整的代码。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Google_login extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->library('session');
}
public function index()
{
include_once(APPPATH."libraries/google-app/vendor/autoload.php");
$google_client = new Google_Client();
$google_client->setClientId('Your_Client_Id');
$google_client->setClientSecret('Secret_Key');
$google_client->setRedirectUri('Redirect_URI');
$google_client->addScope("email");
$google_client->addScope("profile");
if(!empty($_GET['code']))
{
$code = $_GET['code'];
//echo $code; die();
$token = array();
$token = $google_client->fetchAccessTokenWithAuthCode($code);
if(!isset($token["error"])){
$google_client->setAccessToken($token['access_token']);
$google_oauth = new Google_Service_Oauth2($google_client);
$google_account_info = $google_oauth->userinfo->get();
$email = $google_account_info->email;
if($email)
{
$res = $this->db->query("select * from `user_master` where `email` = '".$email."'");
//echo $this->db->last_query(); exit;
$record = $res->row();
$numrows = $res->num_rows();
if($numrows!=0)
{
$this->session->set_userdata('id', $record->id);
$this->session->set_userdata('email', $record->email);
$this->session->set_userdata('geek', $record->geek_name);
$time=date("H:i:s");
$this->db->set('login_time',$time);
$this->db->set('logout_time',"");
$this->db->set('status',"online");
$this->db->where('id',$this->session->userdata('id'));
$this->db->update('user_master');
if($this->session->userdata('id')!="")
{
$query = $this->db->query("select * from `fixergeek_master` where `user_id` = '".$this->session->userdata('id')."'");
$numrow = $query->num_rows();
if($numrow!=0)
{
redirect('fixer');
}
else
{
redirect('asker');
}
// redirect('hostaccountoverview');
}
}
else
{
redirect('/', 'refresh');
}
}
}
}
else {
redirect($google_client->createAuthUrl());
//echo "Test Good";
}
}
}
?>
1条答案
按热度按时间xv8emn3q1#
我也遇到过同样的问题,我在count函数中使用了类型转换参数作为数组
如果在vendor/guzzlehttp/guzzle/src/CurlFactory.php中的if(count($this-〉handles)〉= $this-〉maxHandles)的位置,您可以重新编写此代码,就好像(count((数组)$this-〉handles)〉= $this-〉maxHandles)错误将得到解决