尝试在Google API PHP客户端中使用verifyIdToken()
时,出现以下错误。
PHP Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Wrong recipient, **API KEY OMMITED FOR LENGTH**.apps.googleusercontent.com != :' in C:\includes\gplus\src\Google\Auth\OAuth2.php:621
Stack trace:
#0 C:\includes\gplus\src\Google\Auth\OAuth2.php(497): Google_Auth_OAuth2->verifySignedJwtWithCerts('**TOKEN OMMITED**', Array, '', Array)
#1 C:\includes\gplus\src\Google\Client.php(482): Google_Auth_OAuth2->verifyIdToken('**TOKEN OMMITED**')
#2 C:\tjWEB\googlesignin\token.php(8): Google_Client->verifyIdToken('**TOKEN OMMITED**')
#3 {main}
thrown in C:\includes\gplus\src\Google\Auth\OAuth2.php on line 621
我的PHP代码如下:
<?php
require_once 'C:/includes/gplus/src/Google/autoload.php';
$client = new Google_Client();
$client->setApplicationName("My Application");
$client->setDeveloperKey("**TOKEN OMMITED**");
var_dump($client->verifyIdToken($_POST["idtoken"]));
?>
调用它的页面可用here。我假设每个可能正在阅读它的人都知道如何在他们选择的浏览器中查看源代码。
我在Google上找不到任何解决方案,所以任何帮助都将不胜感激。 谢谢!
答案 0 :(得分:1)
好的,我发现了造成这个问题的原因。
我需要添加
$client->setAuthConfigFile('C:/includes/client_secret.JSON');
给PHP代码,它给了我秘密的API密钥。如果您还没有密钥,可以下载密钥here。
TL; DR因为没有阅读文档而搞砸了