2017-07-16 172 views
0

我有一个非常基本的问题。我想谷歌的标志,从这个链接整合到我的网站: https://developers.google.com/identity/sign-in/web/sign-in谷歌登录按钮不起作用

所以我刚刚成立了一个新的HTML文件,用的正是这种代码

<!doctype html> 
<html> 
<head> 
    <meta name="google-signin-client_id" content="917979196053-718dnj8g6c71jkcim2pvqo17mo0b1819.apps.googleusercontent.com"> 
</head> 
<body> 
    <div id="my-signin2"></div> 
    <script> 
    function onSuccess(googleUser) { 
     console.log('Logged in as: ' + googleUser.getBasicProfile().getName()); 
    } 
    function onFailure(error) { 
     console.log(error); 
    } 
    function renderButton() { 
     gapi.signin2.render('my-signin2', { 
     'scope': 'profile email', 
     'width': 240, 
     'height': 50, 
     'longtitle': true, 
     'theme': 'dark', 
     'onsuccess': onSuccess, 
     'onfailure': onFailure 
     }); 
    } 
    </script> 

    <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script> 
</body> 
</html> 

的代码是从这里: https://developers.google.com/identity/sign-in/web/build-button

现在的问题是,它根本无法正常工作。什么都没有显示在屏幕上,我不知道为什么。另一方面,当我在这里尝试它https://jsfiddle.net/wbzax22e/它以某种方式工作。

这真的很荒唐。有人可以帮我在这里吗?

谢谢!

+0

这是在您的本地机器上吗?或者在一个网站? – HoogleyBoogley

回答

1

您必须在Web服务器上运行此代码。您不能仅在本地访问该文件,否则由于Cookie政策,代码将会出错。如果您希望本地开发服务器查看XAMPP之类的内容或在线查找免费主机。