在angularjs中构建自定义Google登录按钮

时间:2015-08-07 14:04:31

标签: javascript angularjs google-signin google-plus-signin

我的html中有两个观点 1.注册
2登录

我在此链接后使用google google登录按钮:
https://developers.google.com/identity/sign-in/web/build-button自定义图形标题

我在视图登录和注册控制器中执行此操作,

    var googleUser = {};
  var startApp = function() {
    gapi.load('auth2', function(){
      // Retrieve the singleton for the GoogleAuth library and set up the client.
      auth2 = gapi.auth2.init({
        client_id: 'YOUR_CLIENT_ID.apps.googleusercontent.com',
        cookiepolicy: 'single_host_origin',
        // Request scopes in addition to 'profile' and 'email'
        //scope: 'additional_scope'
      });
      attachSignin(document.getElementById('customBtn'));
    });
  };

  function attachSignin(element) {
    console.log(element.id);
    auth2.attachClickHandler(element, {},
        function(googleUser) {
          document.getElementById('name').innerText = "Signed in: " +
              googleUser.getBasicProfile().getName();
        }, function(error) {
          alert(JSON.stringify(error, undefined, 2));
        });
  }

问题是当我第一次在页面加载时转到注册视图,然后点击登录链接进入登录页面,其中我有相同的代码用于谷歌登录按钮
它不起作用。

0 个答案:

没有答案