In my Mac address book I have a group called “Facebook” in which I put my Facebook friends. Over time the group tends to get out of sync with reality so I occasionally check for and repair any inconsistencies. When I view my own Facebook profile it says I have 205 friends but what I wanted was a way of getting Facebook to give me a list that I could compare with my address book. One problem is that Facebook users can change the name associated with their account whenever they feel like it, and for a while some of my friends were doing it with surprising regularity. What I needed was access to the unique id that Facebook must have been using – something that would never change as long as an account existed. So earlier this year I was pleased to discover the Facebook Graph API which “presents a simple, consistent view of the Facebook social graph, uniformly representing objects in the graph (e.g., people, photos, events, and pages) and the connections between them (e.g., friend relationships, shared content, and photo tags)”.
The easiest way to try it out is to use Facebook’s Graph API Explorer app. When you start the app for the first time you will need to either enter an existing access token or click “Get access token”, at which point you will be asked to “Select Permissions” (I don’t select any because the basic ones are included by default) and then “Log in with Facebook”. Once you have a token you can use the “Submit” button to submit API queries, the default one being to get information about your own user account (id, name, first_name, last_name, link, username, gender, timezone, locale, verified, updated_time and type). Under the “Submit” button is a list of “Connections” and if you click on “friends” you will see a list of all your friends (name and unique numerical id). Rather than copying and pasting this into a file I used curl on the command line to download and save my friend list. If $ID is my id and $TOKEN is a valid token (they expire after a while) then the command is:
curl https://graph.facebook.com/$ID/friends?access_token=$TOKEN > friends
Using this method I obtained a list of 200 people and added their unique ids to their address book entries for future cross referencing. But remember my Facebook profile says I have 205 friends, so what about the remaining five? I can view their profiles on Facebook but for some reason they are not found by the API query and I can’t think of anything they have in common which would explain their omission. By the way, if you want a graphical view of your Facebook friend network and you are OK with something that uses Java then TouchGraph seems pretty good (it also fails to list the same five friends).