使用Facebook Graph API获取用户的朋友列表 [英] Using the Facebook Graph API to get a list of a user's friends

查看:537
本文介绍了使用Facebook Graph API获取用户的朋友列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要抓住我应用的朋友列表的用户,以过滤在朋友选择器中显示的用户。我知道我可以打电话给以下列表:

I need to get a hold of a user of my app's list of friends to filter the users that show up in a friend picker. I know I can call the following and get the list:

https://graph.facebook.com/me/friends?access_token=<access_token>

我用自己的帐号在地址栏中尝试过,似乎正好像我需要的那样工作它到问题是,我不知道如何在js文件中使用它。我尝试调用它并使用jquery调用获取数据,但似乎没有任何有用的帮助。

I tried it out in the address bar with my own account and it seems to work exactly as I need it to. Problem is, I don't know how to make use of it in a js file itself. I tried calling it and getting the data out with a jquery call but it doesn't seem to return anything helpful.

$.get("https://graph.facebook.com/me/friends",
    {access_token: <access_token>},
    function(data){ document.write("Data Loaded: " + data);});

我应该如何在我的js文件中调用这个,然后实际使用这些信息?谢谢。

How should I be calling this in my js files and then actually make use of the information? Thanks.

推荐答案

更新:根据 / me / friends 将会返回 strong> app friends 。

UPDATE: As per the changes introduced in V2.0, /me/friends will return app friends only.

正确的方法是使用 Facebook Javascript-SDK ,如下所示:

The right way to do that is by using the Facebook Javascript-SDK, something like this:

function getFriends() {
    FB.api('/me/friends', function(response) {
        if(response.data) {
            $.each(response.data,function(index,friend) {
                alert(friend.name + ' has id:' + friend.id);
            });
        } else {
            alert("Error!");
        }
    });
}

请注意:


  1. 我也在这里使用jQuery

  2. 在调用此功能之前,您可能需要检查用户是否已连接。

这篇关于使用Facebook Graph API获取用户的朋友列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆