Php 谷歌+;登录api问题
我正在尝试在我的应用程序中实现google+oauth2登录,目前遇到了一些问题 我主要是按照写的 这个例子似乎使用了很多像twig这样的库,但我使用的是maining纯php,我不认为这部分会导致任何错误 我面临的第一个问题是没有找到Php 谷歌+;登录api问题,php,oauth,google-plus,Php,Oauth,Google Plus,我正在尝试在我的应用程序中实现google+oauth2登录,目前遇到了一些问题 我主要是按照写的 这个例子似乎使用了很多像twig这样的库,但我使用的是maining纯php,我不认为这部分会导致任何错误 我面临的第一个问题是没有找到Google\u HTTPRequest。 我在某个地方读到,composer将其命名为Google\u HTTP\u Request,所以我改变了这一点,它似乎已经解决了这个问题 然后php抱怨我在对一个非静态函数进行静态调用getIo()。 所以我改为:改为-
Google\u HTTPRequest
。
我在某个地方读到,composer将其命名为Google\u HTTP\u Request
,所以我改变了这一点,它似乎已经解决了这个问题
然后php抱怨我在对一个非静态函数进行静态调用getIo()
。
所以我改为:
改为->
,因为这对我来说是有意义的
然后我得到了错误
PHP Fatal error: Call to undefined method Google_IO_Curl::authenticatedRequest()
这可能和我的改变有关
我正在运行的代码是
$google = new Google_Client();
$google->setApplicationName('Hamster Weebly');
$google->setClientId('CLIEnTID');
$google->setClientSecret('himitsudesuyo');
$google->setRedirectUri('postmessage');
$google->authenticate($_POST['AUTH_CODE']);
$token = json_decode($google->getAccessToken());
//$attrbutes = $google->verifyIdToken($token->id_token, '375022219321-us60lmg2cmeoj1aqpl784t7pbl1kg3jv.apps.googleusercontent.com')->getAttributes();
//error_log($attrbutes['payload']['sub']);
$reqUrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' . $token->access_token;
$req = new Google_Http_Request($reqUrl);
$tokenInfo = json_decode($google->getIo()->authenticatedRequest($req)->getResponseBody());
if ($token->error)
{
http_response_code(500);
exit;
}
// Make sure the token we got is for the intended user.
if ($tokenInfo->userid != $gPlusId) {
http_response_code(401);
echo json_encode("Token's user ID doesn't match given user ID");
exit;
}
// Make sure the token we got is for our app.
if ($tokenInfo->audience != CLIENT_ID)
{
http_response_code(401);
echo json_encode("Token's client ID does not match app");
exit;
}
我的问题是什么?行中:
$tokenInfo = json_decode($google->getIo()->authenticatedRequest($req)->getResponseBody());
getIo()
应该更改为getAuth()
,因为(我认为)api中存在迁移
在那之后,我遇到了另一个我更改的错误:if($token->error)
到if(isset($tokenInfo->error))
祝你好运 行中:
$tokenInfo = json_decode($google->getIo()->authenticatedRequest($req)->getResponseBody());
getIo()
应该更改为getAuth()
,因为(我认为)api中存在迁移
在那之后,我遇到了另一个我更改的错误:if($token->error)
到if(isset($tokenInfo->error))
祝你好运 行中:
$tokenInfo = json_decode($google->getIo()->authenticatedRequest($req)->getResponseBody());
getIo()
应该更改为getAuth()
,因为(我认为)api中存在迁移
在那之后,我遇到了另一个我更改的错误:if($token->error)
到if(isset($tokenInfo->error))
祝你好运 行中:
$tokenInfo = json_decode($google->getIo()->authenticatedRequest($req)->getResponseBody());
getIo()
应该更改为getAuth()
,因为(我认为)api中存在迁移
在那之后,我遇到了另一个我更改的错误:if($token->error)
到if(isset($tokenInfo->error))
祝你好运 getAuth运行时似乎没有错误,但tokeninfo似乎为空。有这方面的文件吗?谢谢如果这个答案解决了你的问题,请接受它作为答案。;-)非常好,谢谢。谷歌真的需要更新他们的API手册。。。这是我第二次被困在使用他们贬值的手册中,LolgetAuth似乎运行正常,但tokeninfo似乎是空的。有这方面的文件吗?谢谢如果这个答案解决了你的问题,请接受它作为答案。;-)非常好,谢谢。谷歌真的需要更新他们的API手册。。。这是我第二次被困在使用他们贬值的手册中,LolgetAuth似乎运行正常,但tokeninfo似乎是空的。有这方面的文件吗?谢谢如果这个答案解决了你的问题,请接受它作为答案。;-)非常好,谢谢。谷歌真的需要更新他们的API手册。。。这是我第二次被困在使用他们贬值的手册中,LolgetAuth似乎运行正常,但tokeninfo似乎是空的。有这方面的文件吗?谢谢如果这个答案解决了你的问题,请接受它作为答案。;-)非常好,谢谢。谷歌真的需要更新他们的API手册。。。这是我第二次被困在使用他们的折旧手册Lol