简体   繁体   English

仅显示1个Facebook朋友-使用FB Javascript SDK jQuery

[英]Only 1 Facebook friends is shown - using FB Javascript SDK jQuery

I'm trying to show a list of all Facebook friends of the logged in user. 我正在尝试显示已登录用户的所有Facebook朋友的列表。 However, using the code as shown below only 1 Facebook friend is shown - instead of all. 但是,使用如下所示的代码,仅显示1个Facebook朋友-而不是全部。 Anybody any idea what might the issue? 任何人都知道可能会出什么问题吗? I'm using the Facebook Javascript SDK together with jQuery. 我正在使用Facebook Javascript SDK和jQuery。

Thanks! 谢谢! Ron 罗恩

      FB.api( {
        method: 'fql.query',
        query: 'SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid1 FROM      friend WHERE uid2 = ' + FB.getSession().uid +')'
      },
      function(response) { 
        for(i=0;i<response.length;i++) {
            $('#friend-info').html('<img src="http://graph.facebook.com/' + response[0].uid + '/picture"><br />').fadeIn('fast');
            }
        } 
      );

Looks to me like you mean to do this: 在我看来,您的意思是:

response[i] instead of response[0] response[i]而不是response[0]

i is the incrementing variable but you're using 0 as the index each time. i是递增变量,但每次都使用0作为索引。

And as Jimmy Sawczuk mentioned, use append() instead of html() (which overwrites the existing html): 就像Jimmy Sawczuk提到的那样,请使用append()而不是html() (它会覆盖现有的html):

Full code with those fixes: 具有这些修复程序的完整代码:

  FB.api( {
    method: 'fql.query',
    query: 'SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid1 FROM      friend WHERE uid2 = ' + FB.getSession().uid +')'
  },
  function(response) { 
    for(i=0;i<response.length;i++) {
        $('#friend-info').append('<img src="http://graph.facebook.com/' + response[i].uid + '/picture"><br />').fadeIn('fast');
        }
    } 
  );

However, it looks like Phil probably has a solution for you that could make more sense overall. 但是,看起来Phil可能为您提供了一个可以从总体上更有意义的解决方案。

$.html覆盖容器中的所有html,因此,除了Wesley Murch建议的内容外,您还应该将.html更改为.append

If you're just after a list of friends, why not use the Graph API instead of a query 如果您只是在好友列表之后,为什么不使用Graph API而不是查询

FB.api('/me/friends?fields=uid,name,picture', function(response) {
    for(var i = 0; i < response.length; i++) {
        var friend = response[i];
        // etc
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM