Google登录错误-gapi.client.plus未定义 [英] Google sign in error-gapi.client.plus is undefined

查看:62
本文介绍了Google登录错误-gapi.client.plus未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google plus API从我的网站中的查看者那里获取电子邮件ID.

I am using Google plus API to get email id from viewers in my website.

Google参考: https://developers.google.com/+/web /signin/add-button

Google reference:https://developers.google.com/+/web/signin/add-button

问题是,当我单击登录按钮时,在浏览器控制台中出现错误"TypeError:gapi.client.plus未定义".

The problem is when i click signin button i getting error "TypeError: gapi.client.plus is undefined" in browser console.

解决方法.

我的代码:

      <script src="https://apis.google.com/js/client:plusone.js?onload=signinCallback" type="text/javascript"></script>

      <span id="signinButton">
        <span class="g-signin" 
            data-callback="signinCallback"
            data-clientid="*****************.apps.googleusercontent.com"
            data-cookiepolicy="single_host_origin" 
            data-scope="profile">
        </span>
     </span>

function signinCallback(authResult) {

    gapi.client.load('plus', 'v1',function(){});

if (authResult['status']['signed_in']) {
    alert("login success");
    document.getElementById('signinButton').setAttribute('style',
            'display: none');

    var request = gapi.client.plus.people.get({
        'userId' : 'me'
    });
    request.execute(function(resp) {
        var email = '';
        if(resp['emails'])
        {
            for(var i = 0; i < resp['emails'].length; i++)
            {
                if(resp['emails'][i]['type'] == 'account')
                {
                    email = resp['emails'][i]['value'];
                }
            }
        }
        alert("email ="+email);
        console.log('ID: ' + resp.id);
        console.log('Display Name: ' + resp.displayName);
        console.log('Image URL: ' + resp.image.url);
        console.log('Profile URL: ' + resp.url);
    });
} else {
    alert("login unsuccessful");
    console.log('Sign-in state: ' + authResult['error']);
}

}

推荐答案

我相信问题可能是在params json中的scope属性作为signIn API的参数传递的.

I belive the issue could be scope property in the params json passed as parameter for signIn API.

范围参数应包含以下网址

Scope parameter should contain below urls

" https://www.googleapis.com/auth/plus.login "
" https://www.googleapis.com/auth/plus.me "

"https://www.googleapis.com/auth/plus.login"
"https://www.googleapis.com/auth/plus.me"

,可能是/userinfo.email、/userinfo.profile

and may be /userinfo.email, /userinfo.profile

这篇关于Google登录错误-gapi.client.plus未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆