【发布时间】:2021-05-20 13:27:07
【问题描述】:
我正在尝试使用 google API 登录,但由于某种原因,$_GET["code"] 和 $this->request->getVar('code') 都是空的,因此我无法获取我的令牌。我试过 $_GET["code"] 而不是 $this->request->getVar('code') 但没有任何效果:
我正在关注这个视频教程:click here
public function signup_with_gmail() {
require_once APPPATH.'Libraries\vendor\autoload.php';
$google_client = new \Google_Client();
//$google_client->setApplicationName("pharma");
$google_client->setClientId('clientID');
$google_client->setClientSecret('SECRET');
$google_client->setRedirectUri('http://localhost/pharma/User/sign_in');
$google_client->addScope('email');
$google_client->addScope('profile');
print_r($this->request->getVar('code') === NULL);
print_r($_GET['code']);
if ($this->request->getVar('code') != NULL) {
$token = $google_client->fetchAccessTokenWithAuthCode($this->request->getVar('code'));
if(!$token['error']){
$google_client->setAccessToken($token['access_token']);
$session->set('access_token', $token['access_token']);
//now get profile data create another object
$google_service = new \Google_Service_Oauth2($google_client);
$data = $google_service->userinfo->get();
print_r($data);
}
}
print_r($data);
}
【问题讨论】:
-
我检查了 github 堆栈溢出但都与令牌刷新有关,但我的问题是 $_GET['code'] 或 $this->request->getVar('code')应该从谷歌返回一些东西,但它是空的
标签: google-oauth codeigniter-4