1

私のWebサイトでは、Facebook Javascript SDKを使用して、ユーザーのFacebookの友達を表示したいと思います。非同期スクリプトをロードするとき、私は次のコードを使用します:

window.fbAsyncInit = function() {               
  FB.init({appId: 'MYAPPID', status: true, cookie: true, xfbml: true});

  FB.api('/me/friends', function(response){
      var divTarget=document.getElementById("friends-list-container");
      var data=response.data;
      for (var friendIndex=0; friendIndex<data.length; friendIndex++)
    {
           var divContainer = document.createElement("div");
           divContainer.innerHTML="<b>" + data[friendIndex].name + "</b>";
           divTarget.appendChild(divContainer);
    }
  });  
};

私は正しいパーマを求めたと思います:'friends_about_me'、しかしそれは機能しません。

誰かアイデアはありますか?

最高、ニューベン

4

1 に答える 1

1

ユーザーの友達を取得するように依頼する必要はありませんがfriends_about_me、ユーザーを承認する必要があります(これは、提供したコードでは実行されません)。また、status取得の非同期性のため、ユーザーが既にログインしていることを確認する必要があります。彼の友達をフェッチする前に。

callbackまた、 :にエラーチェックを追加しても問題はありません。

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    FB.api('/me/friends', function(response){
      if (response && response.data){
        // Handle response
      } else {
        console.log('Something goes wrong', response);
      }
    });
  }
});
于 2012-06-11T12:18:59.217 に答える