首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >google身份验证过期令牌

google身份验证过期令牌
EN

Stack Overflow用户
提问于 2015-08-18 21:23:08
回答 1查看 239关注 0票数 0

我需要恢复用户信息后,javascript谷歌登录。身份验证工作良好,我将googleUser.Ka对象发送到我的php,其中有以下代码

代码语言:javascript
运行
复制
$api = new Google_Client();
$api->setApplicationName($this->_configCustomer['google']['api']['application_name']);
$api->setClientId($this->_configCustomer['google']['api']['client_id']); // Set Client ID
$api->setClientSecret($this->_configCustomer['google']['api']['client_secret']); //Set client Secret
$api->setAccessType('online'); // Access method
$api->setScopes(array('https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'));
//$api->setRedirectUri('http://www.infotuts.com/demo/googlelogin/login.php');
$service = new Google_Service_Plus($api);
$oauth2 = new \Google_Service_Oauth2($api);
$api->setAccessToken(json_encode($_POST));

//ADDED AFTER ERROR
if($api->isAccessTokenExpired()) {
    $api->authenticate();
    $NewAccessToken = json_decode($api->getAccessToken());
    $api->refreshToken($NewAccessToken->refresh_token);
}
//END ADDED AFTER FIRST ERROR


//$api->authenticate($_POST['access_token']);
if ($api->getAccessToken()) {
    $data = $service->people->get('me');
    $user_data = $oauth2->userinfo->get();
    var_dump($user_data);
    die();
}

此代码生成错误:

代码语言:javascript
运行
复制
The OAuth 2.0 access token has expired, and a refresh token is not available. Refresh tokens are not returned for responses that were auto-approved.

我添加了注释中的代码,请按照下面的链接

OAuth 2.0 access token has expired, and a refresh token is not available

但是在php的最后一个版本中,身份验证方法需要$code参数。那是什么?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-19 12:47:10

我就这样解决了

代码语言:javascript
运行
复制
$api = new Google_Client();
$api->setApplicationName($this->_configCustomer['google']['api']['application_name']);
$api->setClientId($this->_configCustomer['google']['api']['client_id']); // Set Client ID
$api->setClientSecret($this->_configCustomer['google']['api']['client_secret']); //Set client Secret
$api->setAccessType('online'); // Access method
$api->setScopes(array('https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'));
$api->setRedirectUri('postmessage');
$result = $api->verifyIdToken($_POST['id_token']);

我发送从ajax登录获取的id_token,并使用客户端库的verifyIdToken方法恢复用户信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32082799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档