Tutorial: Plotting your Facebook friend network using NetworkX and python-louvain

Last week I published an article showing you how I built a friend graph using you Facebook data.

This article is a detailed version showing you how to do it yourself. Here’s what we’ll end up with:

Facebook friend network (click to enlarge)

Warning: To make such a graph, you need to scape all your mutual friends. Scrapping is automated but can take a few hours.

Let’s get started !

Scrapping the data

Facebook does not let you access friends you have in common via any API, so we’ll have to scrappe the data.

Clone the repo, and install requirements:

git clone https://github.com/EliotAndres/facebook-friend-graph cd facebook-friend-graph pip install -r requirements.txt

The scrapping script will open a Chrome window and go to each of your friends profile. It’ll then read the DOM to save your mutual friends.

It’s using the Chrome drive, so you must also install it. Once done, you can run:

python facebookFOF.py

The script will prompt you for your username/password. You’ll see a progress bar. It will periodically save the graph. So if it fails, you can just restart it and it’ll start where it stopped. It can take up to a few hours depending on your connection.

You’ll end up with a .pickle file containing you friend graph information. Now let’s plot this data !

Building the graph

You’ll find all the details in the notebook below. It’s available here.

Conclusion

The graph should be made of differentiated clusters. You can hover over the clusters to see your friends names. You can also play with the parameters and the colors to make it suit your needs. If you encounter any problem, open an issue on Github.

Acknowledgements

Original notebook author: Lucas Allen, original code

Original scrapping code (Python 2) here