如何从 api 获取整个 Facebook 好友列表

lou*_*uay 4 c# facebook facebook-graph-api

有没有办法使用 api 获取整个 Facebook 好友列表!

我尝试了很多事情,这是我的镜头:

FacebookClient f = new FacebookClient(access_token);
f.IsSecureConnection = true;
dynamic friendlist = await f.GetTaskAsync(@"https://graph.facebook.com/me/friendlists?access_token="+access_token);
t.Text = JsonConvert.SerializeObject(friendlist);
Run Code Online (Sandbox Code Playgroud)

但我得到的只是空数据!
谁能帮我?

lus*_*chn 6

好友列表端点已被弃用,正如您在重大更改日志中看到的那样:https ://developers.facebook.com/docs/graph-api/changelog/writing-changes#tagged-users-4-4

无论如何,这不会是你所期望的,它只是用于列表,而不是直接的朋友。很长一段时间以来,不可能接触到所有的朋友。您只能获取授权您的应用程序的用户/好友的数据。您可以/me/friends为此使用端点。

关于获取所有朋友的另一个线程:Facebook Graph API v2.0+ - /me/friends 返回空,或仅返回也使用我的应用程序的朋友

  • 我强烈建议不要尝试安装那些“谁查看了您的个人资料”应用程序。从 graph api v2.0 开始,不可能找到所有朋友(现在是 v2.12),并且永远不可能找到查看过您个人资料的人。人们真的还相信这一点吗?:/ (3认同)
  • 他们只能抓取个人资料,这在 Facebook 上是不允许的。根本没有办法。我将在我的答案中添加另一个线程的链接,其中 Facebook 员工回答了问题。如果你不相信我,也许你相信 Facebook ;) (2认同)
  • 这些游戏应用程序仍然只能访问已经玩过该游戏的朋友 (2认同)

Nit*_*ant 5

这不是 API 方式,而是适合想要一次性下载好友列表的初学者

  1. 前往好友列表页面: https: //www.facebook.com/friends/list
  2. 一直向下滚动,以便加载所有好友列表
  3. 按 F12 打开开发者工具,单击控制台选项卡 火狐开发者工具控制台 火狐

A. 在控制台中显示 复制粘贴以下脚本并按 Enter 键。

    var accumulated = "";
    for (var el of document.querySelectorAll('[data-visualcompletion="ignore-dynamic"]')) {
        var name = el.getAttribute("aria-label");
        if(name!= null && name != "null"){
            accumulated = "Name:"+name +", "+ accumulated;
            console.log(accumulated);
            accumulated = "";
        }else{
            var a = el.getElementsByTagName("a")[0];
            if(a){
                accumulated += "Profile URL: "+ a.getAttribute("href");
                //console.log(a);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

B. 下载 .json 文件, 在控制台中复制粘贴以下脚本,然后按 Enter 键。

    var exportObj = [];
    var accumulated = "";
    for (var el of document.querySelectorAll('[data-visualcompletion="ignore-dynamic"]')) {
        var name = el.getAttribute("aria-label");
        if(name!= null && name != "null"){
            exportObj.push({name: name, profileURL: accumulated});
            accumulated = "";
        }else{
            var a = el.getElementsByTagName("a")[0];
            if(a){
                accumulated += a.getAttribute("href");
            }
        }
    }
    
    var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
    var downloadAnchorNode = document.createElement('a');
    downloadAnchorNode.setAttribute("href",     dataStr);
    downloadAnchorNode.setAttribute("download", "friendsList.json");
    document.body.appendChild(downloadAnchorNode);
    downloadAnchorNode.click();
    downloadAnchorNode.remove();
Run Code Online (Sandbox Code Playgroud)

注:伪代码在firefox中测试