使用googleapi登录我的网站



我正在尝试使用谷歌登录我的网站。我把代码放在jsp页面html代码:

<span id="signinButton">
 <span
class="g-signin"
data-callback="signinCallback"
data-clientid="*********"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schema.org/AddAction"
data-scope="https://www.googleapis.com/auth/plus.login">
 </span>
 </span>

javascript代码:

(function() {
  var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  po.src = 'https://apis.google.com/js/client:plusone.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
 function signinCallback(authResult) {
      if (authResult['status']['signed_in']) {
        // Update the app to reflect a signed in user
        // Hide the sign-in button now that the user is authorized, for example:
        document.getElementById('signinButton').setAttribute('style', 'display: none');
        var request = gapi.client.plus.people.get({
              'userId' : 'me'
            });
        request.execute(function(resp) {
              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 {
        // Update the app to reflect a signed out user
        // Possible error values:
        //   "user_signed_out" - User is signed-out
        //   "access_denied" - User denied access to your app
        //   "immediate_failed" - Could not automatically log in the user
        console.log('Sign-in state: ' + authResult['error']);
      }
    }

如果我把数据范围地址http,我得到错误:

  1. 这是个错误

错误:invalid_request

作用域不允许request_visible_actionshttp://www.googleapis.com/auth/plus.login

  1. 这是个错误

错误:origin_mismatch

应用程序:项目默认服务帐户

如何解决这个问题。我想要使用谷歌api的用户配置文件详细信息?

删除data-requestvisibleactions="http://schema.org/AddAction",确保代码执行的确切URL和路径已在允许来源的应用程序列表中注册。将范围更改为data-scope="profile"

相关内容

  • 没有找到相关文章

最新更新