Cleaning up Facebook “Friend” list

I created my Facebook account in 2007, when Facebook was slowly making its trend in this side of the world. And then I made the worst mistake – adding anyone.

At that time, there was not many with Internet access, and even less had Facebook accounts. As a result of “keeping up with the latest trend” without even fully understanding what it will become in the future, I ended up making many “friends”. This includes a small number of people I know well and many others, including some whom I’ve never met or never talked.

When friend list reached over 2000, I found this makes it really difficult to keep up with the people whom I really care. I even heard complaints like “you never like my posts”. That’s how I wanted to clean up my friend list.

Manual cleaning up of Facebook friend list is cumbersome. I spent many hours making “fair judgements” to remove only 30 – 40. I desperately need an automated tool to analyze my friend list.

Before re-inventing the wheel, I wanted to look at what’s already available. I heard about Wolfram|Alpha Facebook Report somewhere, but sigh! Facebook killed it by deprecating the API (cover story is security). Not only that; there were some third-party apps in Google Play that were capable of analyzing Facebook friend list and telling you what Facebook won’t tell you about your friends. According to the developers, Facebook officials killed such teeny-tiny apps too.

Now we have to re-invent the wheel. I don’t have much time to work on side-projects, but I plan to develop something that exploits the browser DOM. I think a headless browser like phantomjs will be helpful in this case. Since API is deprecated and no more, I feel this is the way forward.

As the initial step, here’s something that everyone can do within a couple of minutes to export friend list to a spreadsheet! It will also include “friends” who had (temporarily) disabled their accounts. Following instructions are for Google Chrome, but I’m sure they will work on Firefox as well.

Go to https://m.facebook.com/friends/center/friends on desktop browser. We are working with the mobile site on desktop browser because it’s lightweight and easier to handle with custom JavaScript.

Open up Developer Tools and go to Console tab. Keyboard shortcut is F12.

Copy-paste the following snippet to Developer Tools Console and hit Enter to run it. I wrote it in raw JavaScript because I’m unfamiliar with the frontend JavaScript library Facebook is using. It automatically scrolls the page to the bottom allowing Facebook load more friends to the browser. Here’s I’m assuming paginated content takes only 1 second per page to load, and 200 “scrolls to the bottom” are enough to load the complete list. You need to wait for 200 x 1 seconds.

var assumedLoadTime = 1000;
var loadCount = 200;

function loadAllFriends (c) {
    if (c == 0) return;
    setTimeout (function () {
        window.scrollTo(0,document.body.scrollHeight);
        c--;
        loadAllFriends ();
    }, assumedLoadTime);
}

loadAllFriends (loadCount);

If browser scroll-down appears to hit its dead-end, proceed to the next step. Otherwise re-run the above code.

Run the next piece of code in Developer Tools Console. Before that please remove whitespaces before and after > and < characters in the last line. 🙂

var text = "";
var dt = document.getElementsByClassName('darkTouch'); // it was easier to figure out this class='darkTouch' thing :)
for (var i=0;i<dt.length;i++) {
	var e = dt[i];
	var nameObj = e.childNodes[0].attributes[1];
	var name = (nameObj ? nameObj.value : "" );
	var hrefObj = e.attributes.href;
	var href = (hrefObj ? "https://web.facebook.com" + hrefObj.value : "" );
	text = text + name + "\t" + href + "\r\n";
}

var newWindow = window.open ("", "_blank");
newWindow.document.write ("< textarea rows=\"50\" cols=\"80\" >" + text + "< /textarea >");

This will open a new window and show your complete friend list as text. Select all, and then copy-paste it into your spreadsheet program. It will have two columns, name of the person and profile link. If the link is empty, which means the person may have disabled their Facebook account. This helped me to identify more than a dozen of dormant Facebook “friends” and remove them within minutes.

The above code and method is just a “proof of concept”. If you don’t want to play with code, I heard that “downloading your facebook data” is also helpful. My mission is bigger. I want to analyze all “friends”, their interactions, likes, comments, etc. to find the best people who deserve to remain with me. Let’s see how it goes.

Cleaning up Facebook “Friend” list

2 thoughts on “Cleaning up Facebook “Friend” list

  1. This is great. Works like a charm.

    One correction: The URL of the mobile version’s friends list should be updated as ‘https://m.facebook.com/friends/center/friends’

    Current URL point to the friend suggestions.

Leave a comment