2011-07-06 69 views

回答

4

onclick事件只是添加到任何您的自定义按钮,并调用它他们的javascript sdk中的FB.login事件。

完整的示例:

<!DOCTYPE html> 
<html> 
<body> 
<div id="fb-root"></div> 
<a href="#" onclick="doLogin();return false;">Custom Login Button</a> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> 
    FB.init({ appId: '**yourAppId**', status: true, cookie: true, xfbml : true }); 

    function doLogin() { 
    FB.login(function(response) { 
     if (response.session) { 
     FB.api('/me', function(response) { 
      alert('Welcome ' + response.name); 
      alert('Full details: ' + JSON.stringify(response)); 
      } 
     ); 
     } 
    } , {perms:''}); 
} 
</script> 
</body> 
</html> 
+0

在哪里,我需要把我的网址。我的网站目前位于本地主机上。 我已经粘贴了你的代码并添加了我的appId,我在fb弹出“给定URL不被应用程序配置允许”时出现这个错误。 – Faizan