Google+的签到/ Singup按钮 [英] Google+ Signin/Singup button

查看:484
本文介绍了Google+的签到/ Singup按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个谷歌+登入/注册按钮添加到我的网站 www.bendali.co.za 。我已经把这个code:

I would like to add a Google + signin/signup button to my website www.bendali.co.za. I have already put in this code:

    <!-- Place this asynchronous JavaScript just before your </body> tag -->
    <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';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
     })();


function signinCallback(authResult) {
  if (authResult['access_token']) {
    // Successfully authorized
    // Hide the sign-in button now that the user is authorized, for example:
    document.getElementById('signinButton').setAttribute('style', 'display: none');
  } else if (authResult['error']) {
    // There was an error.
    // Possible error codes:
    //   "access_denied" - User denied access to your app
    //   "immediate_failed" - Could not automatically log in the user
    // console.log('There was an error: ' + authResult['error']);
  }
}


    </script>

<span id="signinButton">
  <span
    class="g-signin"
    data-callback="signinCallback"
    data-clientid="712370252357.apps.googleusercontent.com"
    data-cookiepolicy="single_host_origin"
    data-requestvisibleactions="http://schemas.google.com/AddActivity"
    data-scope="https://www.googleapis.com/auth/plus.login">

</span>
</span>

我从 https://developers.google.com/+/web/采取它登入/ 。但是,当我preSS它,它给我的对话和一切,我接受它,按钮自败(所有这些是正常的)。但它不记录我或任何东西。我将如何得到它这样做呢?

I have taken it from https://developers.google.com/+/web/signin/. But when I press it, it gives me the dialog and everything and I accept it and the button dissapears (all of which is normal). But it doesn't log me in or anything. How would I get it to do that?

先谢谢了。

推荐答案

我不明白你的code的任何问题,我的机器上的快速测试显示了它的工作。

I don't see any issues with your code and a quick test on my machine shows it working.

您可以测试您是否通过打开JavaScript控制台的Web浏览器,并试图让当前会话访问令牌登录。下面的函数:

You can test whether you are logged in by opening the JavaScript console for your web browser and trying to get the access token for the current session. The following function:

gapi.auth.getToken();

将返回的的,如果您还没有登录,并是这样的:

Will return null if you are not logged in and something like this:

Object {state: "", access_token: "ya29.lkjasdlkjasd....", token_type: "Bearer", expires_in: "3600", code: "4/.....wo8WbjRKPN4WMqTmHjyTFGPeKJnufgI"…}

如果您已经登录,控制台还应该给你约是$ P $从工作pventing在登录code任何错误的详细信息。

if you are logged in. The console also should give you more information about any errors that are preventing the sign-in code from working.

如果你正在寻找做一些更复杂,例如使用户登录到你的网站,你应该用的 Google+的快速入门,以获得如何通过授权用户连接您的服务器的要点,然后拿看看Photohunt ,了解更多COM prehensive网站的例子。

If you are looking to do something more complicated such as log the user into your site, you should start with the Google+ Quickstarts to get the gist of how you can connect your server with the authorized user and then take a look at Photohunt for a more comprehensive site example.

这篇关于Google+的签到/ Singup按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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