Php 谷歌+;服务器端应用的登录身份验证不工作
我正在尝试为wordpress站点添加Google+auth。 我想要的是:在Google+中进行身份验证后,如果用户未在网站上注册,我会将其重定向到输入用户名的页面;如果用户已经注册-它将被登录。 下面是我的js代码:Php 谷歌+;服务器端应用的登录身份验证不工作,php,javascript,wordpress,google-plus,Php,Javascript,Wordpress,Google Plus,我正在尝试为wordpress站点添加Google+auth。 我想要的是:在Google+中进行身份验证后,如果用户未在网站上注册,我会将其重定向到输入用户名的页面;如果用户已经注册-它将被登录。 下面是我的js代码: function doGooglePlusLogin(authResult) { if (authResult['code']) { jQuery('#signinButton').attr('style', 'display: none');
function doGooglePlusLogin(authResult) {
if (authResult['code']) {
jQuery('#signinButton').attr('style', 'display: none');
jQuery.ajax({
url: '<?php echo site_url(); ?>/wp-admin/admin-ajax.php',
type: 'get',
dataType: 'json',
data: {
action: 'login_gplus',
code: authResult['code']
},
success: function(result) {
},
});
} else if (authResult['error']) {
}
}
用户在Google+中成功授权,但在php中我得到以下信息:
致命错误:在/var/www/html/v4/wp content/plugins/social/Google plus/Google api/auth/Google_OAuth2.php:113堆栈跟踪:#0/var/www/html/v4/wp content/plugins/Google plus/Google api/Google_OAuth2.php:113堆栈跟踪:#0/var/www/html/v4/wp content/plugins/social/Google plus/Google api/Google_Client.php(131)中出现未捕获的异常“Google_AuthException”:Google_OAuth2->authenticate(数组'4/ScmpTqEIWt0SJ…'))#1/var/www/html/v4/wp content/plugins/social/Google plus/functions.php(35):Google_客户端->authenticate('4/ScmpTqEIWt0SJ…')#2[内部函数]:login#gplus('')#3/var/www/html/v4/wp includes/plugin.php(406):call u user#func#func数组('login#gplus',Array)#4/var/www/html/v4/wp admin/admin ajax.php(74):在第113行的/var/www/html/v4/wp content/plugins/social/google plus/google api/auth/google_OAuth2.php中插入动作('wp_ajax_nopriv…'))#5{main}
应用内设置重定向指定为的URI。
我做错了什么
编辑:
Google+登录按钮定义:
<span id="signinButton">
<span class="g-signin"
data-callback="doGooglePlusLogin"
data-clientid="<?php echo $this->gplus_client_id; ?>"
data-cookiepolicy="single_host_origin" data-accesstype="offline"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/plus.login">
</span>
</span>
您的代码基本上是正确的,但有一个我可以看到的小怪癖是没有很好的记录!您必须将重定向URI设置为postmessage,而不是您正在使用的URL
$client->setRedirectUri('postmessage');
这是因为它与Javascript交换期间从按钮为令牌设置的URI相匹配。查看位于的示例代码:以查看其实际运行情况。我将确保在文档中添加注释。您是在使用还是自己触发流?请发布显示如何触发此流的前端代码。我们需要查看传递给Google的配置参数。(隐藏你的客户端ID。另外,我们需要在你的PHP端查看你的社交重定向uri的值。我正在使用Google+登录按钮。SOCIAL\u GPLUS\u REDIRECT\u URIS感谢你的帮助。你救了我。OMG!!!!我花了8个小时研究代码,试图摆脱这个愚蠢的REDIRECT\u uri\u不匹配。)
错误!尝试使用编码、不使用、http/https、注册新应用程序、不同子域……哦,我的天啊,我刚刚将postmessage
改为。谷歌伙计们,请记录它!!!!!谢谢,你也救了我!谷歌文档中没有任何内容:(greatttt!!我已经挖掘这个错误好几个小时了。请更新这个页面()上的文档,说明如何正确验证Google_Client()类。事实上,它是神秘的、误导的和令人沮丧的。
$client->setRedirectUri('postmessage');