0
<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/获得了这个脚本,但我找不到我的错误。如何让它像我想要的那样正确工作?

4

1 回答 1

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>
于 2012-07-30T10:04:36.133 回答