Thursday, January 20, 2011

Catch who removed you from Facebook...!

Facebook doesn't send notifications upon unfriending.. although it does when somebody added you.

This blog post explains how to catch people who remove you from Facebook friend list.

Before running the following java program, you need to do the following steps..

0. Go to!/pages/Facebook-Developer/7213347185 and LIKE that page.

1. Go to and click on "Set Up New App"

2. Once done with [1] - go to the link and select your application from the "Test Console" and click on the link which looks like

3. Now a new browser window will be opened up and from the Url - copy the access_token - which is in the query string. Make sure you properly copy the access_token value only - don't mess up with the other query string parameters present in the same Url.

4. Replace the value of the constant ACCESS_TOKEN in code below with the one you got from [3].

5. Download the RestFB jar from here and add it to the classpath of the java program.

6. That's it and whenever you run the following program you will see the friends you made and lost from your previous run.

import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;

import com.restfb.Connection;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.types.User;

public class FacebookTestClient {

 private final static String ACCESS_TOKEN = "126895777dsd7843z4erer7C2.WfdfgQmjj376b_gfdfdf__.3600.1295557200-787236966%7CQ0166mXlhvmBoCXohUDVpfWrYAg";

 public static void main(String[] args) {

  FacebookClient facebookClient = new DefaultFacebookClient(ACCESS_TOKEN);
  Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);

  List<User> list = myFriends.getData();
  Hashtable<String, String> newFriends = new Hashtable>String, String>();
  Hashtable<String, String> oldFriends = loadOldFriends();

  for (Iterator<User> iterator = list.iterator(); iterator.hasNext();) {
   User friend =;
   newFriends.put(friend.getId(), friend.getName());

   if (oldFriends != null) {
    if (!oldFriends.containsKey(friend.getId())) {
     System.out.println("You have a new friend today, " + friend.getName());

  if (oldFriends != null) {
   for (Iterator<Entry<String, String>> iterator = oldFriends.entrySet().iterator(); iterator
     .hasNext();) {
    Entry<String, String> friendEntry =;
    if (!newFriends.containsKey(friendEntry.getKey())) {
     System.out.println("You lost a friend today, " + friendEntry.getValue());




 private static void saveFriends(Hashtable<String, String> friends) {

  try {
   FileOutputStream fileOut = new FileOutputStream("friendlist.ser");
   ObjectOutputStream out = new ObjectOutputStream(fileOut);
  } catch (Exception e) {

 private static Hashtable<String, String> loadOldFriends() {

  Hashtable<String, String> friends = null;

  try {
   if (new File("friendlist.ser").exists()) {
    FileInputStream fileIn = new FileInputStream("friendlist.ser");
    ObjectInputStream in = new ObjectInputStream(fileIn);
    friends = (Hashtable<String, String>) in.readObject();
  } catch (Exception e) {
  return friends;


Prabath Abeysekara said...

WOW! Awesome.!!

Jayanga Kaushalya said...

That's a thing I wanted...!

sLoP said...

For anyone who doesn't want to code and likes a nice integration directly into Facebook, try this userscript: (using it myself, works perfectly!)

lahiru said...

Totally waste of your time... to find who removed you from FB.

Prabath said...

FB has moved to OAuth and the sample in this blog post won't work any more..