V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
xiaolvmu
V2EX  ›  JavaScript

问一个 Google+ Login API 的回调函数问题。

  •  
  •   xiaolvmu · 2014-12-08 02:04:47 +08:00 via Android · 3136 次点击
    这是一个创建于 3429 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #求助

    我是小白,对javascript一无所知......
    在模板文件中添加如下代码(</body>之前)
      <script type="text/javascript">
      (function() {
        var po = document.createElement('script');
        po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/client:plusone.js? onload=render';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(po, s);
      })();

      function render() {
        gapi.signin.render('customBtn', {
          //'callback': 'signinCallback',
          'clientid': 'http://876129027227-m4n8ghl8s6g8slbs2c48eh6o4fbdn4ff.apps.googleusercontent.com',
          'cookiepolicy': 'single_host_origin',
          'requestvisibleactions': 'http://schemas.google.com/AddActivity',
          'scope': 'https://www.googleapis.com/auth/plus.login'
        });
      }
      </script>
      <style type="text/css">
        #customBtn {
          display: inline-block;
          background: #cc3732 ;
          color: white;
          width: 175px;
          border-radius: 5px;
        }
        #customBtn :hover {
          background: #e74b37 ;
          cursor: hand;
        }
        span.label {
          font-weight: bold;
        }
        span.icon {
          background: url('/+/images/branding/btn_red_32.png') transparent 10px 50% no-repeat;
          display: inline-block;
          vertical-align: middle;
          width: 40px;
          height: 40px;
        }
        span.buttonText {
          display: inline-block;
          vertical-align: middle;
          padding-left: 40px;
          padding-right: 40px;
        }
      </style>
      <span class="label">Sign in with:</span>
      <div id="customBtn" class="customGPlusSignIn">
        <span class="icon"></span>
        <span class="buttonText">Google</span>
      </div>

    这是添加Google登录按钮的。

    想问一下,这个回调函数具体怎么编写呢?我没有接触过JavaScript,不懂怎么编写……
    例如我想实现这样的效果:
    用户授权,返回True,则跳转到注册页面,注册一个帐号,以后用户登录Google帐号就可以访问论坛(也就是绑定了Google帐号)
    用户不授权,返回False,不过由于论坛只有注册才可以进入,按钮的页面正是登录界面,因此不用做任何反应。

    这改怎么编写呢?
    2 条回复    2014-12-08 02:14:24 +08:00
    xiaolvmu
        1
    xiaolvmu  
    OP
       2014-12-08 02:05:31 +08:00 via Android
    不好意思打了几个错别字
    xiaolvmu
        2
    xiaolvmu  
    OP
       2014-12-08 02:14:24 +08:00 via Android
    就是 Techllage.com ……网页底部的一个按钮
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3117 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:41 · PVG 08:41 · LAX 17:41 · JFK 20:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.