小编Pet*_*ter的帖子

Google+登录服务器端应用无法正常使用

我尝试为wordpress网站添加Google+身份验证.我想要的是:如果用户未在网站上注册,则在Google+中验证后 - 我将其重定向到他输入用户名的页面; 如果用户已经注册 - 它将登录.这里我的js代码:

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']) {
    }
}
Run Code Online (Sandbox Code Playgroud)

这里是我的PHP代码:

function login_gplus() {
$response = array();

if (isset($_GET['code']) && !empty($_GET['code'])) {
    @session_start();
    $client = new Google_Client();
    $client->setApplicationName('Test');
    $client->setAccessType('offline');
    $client->setClientId(get_option(SOCIAL_GPLUS_CLIENT_ID));
    $client->setClientSecret(get_option(SOCIAL_GPLUS_CLIENT_SECRET));
    $client->setDeveloperKey(get_option(SOCIAL_GPLUS_API_KEY));
    $client->setRedirectUri(get_option(SOCIAL_GPLUS_REDIRECT_URIS));
    $client->setApprovalPrompt('auto');

    $code = $_GET['code'];
    $client->authenticate($code);

    $token = json_decode($client->getAccessToken());
    $reqUrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' . $token->access_token; …
Run Code Online (Sandbox Code Playgroud)

javascript php wordpress google-plus

9
推荐指数
1
解决办法
4339
查看次数

标签 统计

google-plus ×1

javascript ×1

php ×1

wordpress ×1