FB-Connect简单脚本不起作用

时间:2012-07-29 13:25:30

标签: facebook fbml

<html xmlns="http://www.w3.og/1999/xhtml" xmlns:fb="http://facebook/2008/fbml">
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>


<fb:login-button onlogin="update_user_box();"></fb:login-button>

<script>
function update_user_box(){
user_box = document.getElementById("user");
user_box.InnerHtml = "<span>"
+"<fb:profile-pic uid='loggedinuser' facebook-logo=true></fb:profile-pic>"
FB.XFBML.Host.parseDomTree();
}
FB.init("APP_ID","xd_reciever.htm");

</script>
<div id="user"></div>

这是我的剧本。其实我想从facebook connect获取登录用户的个人资料图片。但这不起作用,我从http://mashable.com/2008/12/11/facebook-connect-blog/得到了这个脚本,我无法找到我的错误。如何正确地工作 - 我想要什么?

1 个答案:

答案 0 :(得分:0)

这对你有用......

  // assume we are already logged in
  FB.init({appId: 'YOUR_APP_ID', xfbml: true, cookie: true});

  function showProfile(response) {

if (response.authResponse) {
      //user is already logged in and connected
      var userInfo = document.getElementById('user');
      FB.api('/me', function(response) {
        userInfo.innerHTML = '<img src="https://graph.facebook.com/' + response.id + '/picture">' + response.name;
      });
    } 
  }

  // run once with current status and whenever the status changes
  FB.getLoginStatus(showProfile);
  FB.Event.subscribe('auth.statusChange', showProfile); 


  (function() {
          var e = document.createElement('script'); e.async = true;
          e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
          document.getElementById('fb-root').appendChild(e);
  }());

然后有两个div用于登录按钮和存储配置文件信息。

<div class="fb-login-button" autologoutlink="true"></div>
<div id="user"></div>