未捕获的异常'Google_Auth_Exception',并显示消息'获取OAuth2访问令牌时出错,消息:'invalid_request:

时间:2015-03-20 14:38:42

标签: php codeigniter google-api google-plus google-api-php-client

我正在尝试使用codeigniter Framework在网站上实施第三方google plus身份验证,但我遇到了一些问题

我导入了librairies并在控制器注册的构造函数中初始化了google键:

public function __construct(){
        parent::__construct();
        //Google Auth
        require_once APPPATH ."libraries/google-api-php-client-master/src/Google/autoload.php";
        include_once APPPATH . "libraries/google-api-php-client-master/src/Google/Client.php";
        include_once APPPATH . "libraries/google-api-php-client-master/src/Google/Service/Oauth2.php";
        $this->client_google_id = 'google_id';
        $this->client_google_secret = 'google_secret';
        $this->redirect_google_uri = 'http://mysite/signup/google';
        $this->simple_google_api_key = 'google_key';
        $this->client_google = new Google_Client();
    }

当我点击登录谷歌按钮时,我们在注册

中启动登录方法
function login()
{
      // Create Client Request to access Google API
            $this->client_google->setApplicationName("Kukkea");
            $this->client_google->setClientId($this->client_google_id);
            $this->client_google->setClientSecret($this->client_google_secret);
            $this->client_google->setRedirectUri($this->redirect_google_uri);
            $this->client_google->setDeveloperKey($this->simple_google_api_key);
            $this->client_google->addScope("https://www.googleapis.com/auth/plus.login");

            $GoogleAuthUrl = $this->client_google->createAuthUrl();
            $data['GoogleAuthUrl'] = $GoogleAuthUrl;
}

google login后重定向的方法是

 function google()
    {

        // Add Access Token to Session
        if (isset($_GET['code'])) {
            $this->client_google->authenticate($_GET['code']);
            $_SESSION['access_token'] = $this->client_google->getAccessToken();
            header('Location: ' . filter_var($this->redirect_google_uri, FILTER_SANITIZE_URL));

        }
}

但我有这个错误

    Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_request: Client must specify either client_id or client_assertion, not both'' in C:\xampp\htdocs
\Web\application\libraries\google-api-php-client-master\src\Google\Auth\OAuth2.php:119 Stack trace: #0 C:\xampp\htdocs\Web\application\libraries\google-api-php-client-master\src\Google\Client.php(125): 
Google_Auth_OAuth2->authenticate('4/XsDs2IRpk893t...') #1 C:\xampp\htdocs\Web\application\controllers\signup.php(487): 
Google_Client->authenticate('4/XsDs2IRpk893t...') #2 [internal function]: Signup->google() #3 C:\xampp\htdocs\Web\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #4 C:\xampp\htdocs\Web\index.php(202): require_once('C:\\xampp\\htdocs...') #5 
    {main} thrown in C:\xampp\htdocs\Web\application\libraries\google-api-php-client-master\src\Google\Auth\OAuth2.php on line 119

我该如何解决?

0 个答案:

没有答案