Vous êtes sur la page 1sur 3

25/03/2019 How To Detect Who Unfriended You on Facebook?

- CodeProject

How To Detect Who Unfriended You on Facebook?


Hussein_Hazimeh, 24 Mar 2019

In this code, I will show you how to detect who unfriended you on Facebook. It compares your original friend list with your current
friend list, and lists names of all the friends who removed you.

Introduction
Facebook comprises more than 2 billion active users each month in 2018! One of the services of this social network is sending you
notifications about the new friend requests. Despite this service, Facebook will not let you be aware of unfriend events. You can only
realize if someone removes you by checking the number of friends.

In this context, I wrote a Java code with Selenium API that gets all the friend names from your Facebook profile and saves them into
an Excel file. Then you can run this code each time you want, and get a result of all the names of friends who removed you.

Using the Code


To run the code properly, you should install and configure the Selenium web driver on your PC. To do this, please follow this article:
ChromeDriver - WebDriver for Chrome - Getting Started.

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;

import org.json.JSONException;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

/**
* @author hussein.hazimeh
* 23.03.2019
*
*/
public class UnfriendDetector{
private static String dir = "C:/Users/husseiny.hazimeh/Desktop/chromedriver_win32";
private static WebDriver driver;
private String inputFile;

public static void main(String[] args) throws IOException{


UnfriendDetector cc = new UnfriendDetector();
https://www.codeproject.com/Articles/1280631/How-To-Detect-Who-Unfriended-You-on-Facebook?display=Print 1/3
25/03/2019 How To Detect Who Unfriended You on Facebook? - CodeProject
ArrayList<String> newList = cc.get_new_list();

/* the original friend list fetched from Excel file.


* To write this original list to the Excel file, change the body of get_new_list()
* function and write the crawled friend names into a text file
* then copy/paste these names into an excel sheet,
* and finally save this sheet as .xls format
* you will then compare all the new lists (live lists)
* with this baseline Excel list and get
* all the friend names who unfriend you.
*/

cc.setInputFile("d:/friend2.xls");
ArrayList<String> oldList = cc.get_old_list();
System.out.println("i am in excel file");
System.out.println(newList.size() + " current friend list : " + newList);
System.out.println(oldList.size() + " old friend list : " + oldList);
oldList.removeAll(newList);
System.out.println("UnFreind_list : " + oldList);
}

public ArrayList<String> get_new_list() throws IOException


{
System.setProperty("webdriver.chrome.driver", dir +"\\chromedriver.exe" );
driver = new ChromeDriver();

driver.get("https://www.facebook.com/");

driver.findElement(By.name("email")).sendKeys("your_facebook_email");
driver.findElement(By.name("pass")).sendKeys("your_facebook_pass");
driver.findElement(By.id("loginbutton")).click();

driver.get("https://www.facebook.com/your_facebook_id/friends?
lst=100002506107371%3A100002506107371%3A1553263520&source_ref=pb_friends_tl");

JavascriptExecutor js = ((JavascriptExecutor) driver);


for(int j=0;j<2500;j++) js.executeScript("window.scrollTo
("+j+", document.body.scrollHeight)");

List<WebElement> e = driver.findElements(By.xpath(".//*[@class='fsl fwb fcb']"));


ArrayList<String> friends = new ArrayList<String>();
for (int i=0;i<e.size();i++)
{
friends.add(e.get(i).getText());
}

driver.close();
return friends;
}

public void setInputFile(String inputFile) {


this.inputFile = inputFile;
}
public ArrayList<String> get_old_list() throws IOException {
ArrayList<String> friends = new ArrayList<String>();
File inputWorkbook = new File(inputFile);
Workbook w;
try {

WorkbookSettings workbookSettings = new WorkbookSettings();


workbookSettings.setEncoding( "ISO-8859-1" );

w = Workbook.getWorkbook( inputWorkbook, workbookSettings );

Sheet sheet = w.getSheet(0);

for (int j = 0; j < sheet.getColumns(); j++) {


for (int i = 0; i < sheet.getRows(); i++) {
Cell cell = sheet.getCell(j, i);
CellType type = cell.getType();

if (type == CellType.LABEL) {
friends.add(cell.getContents());
}

https://www.codeproject.com/Articles/1280631/How-To-Detect-Who-Unfriended-You-on-Facebook?display=Print 2/3
25/03/2019 How To Detect Who Unfriended You on Facebook? - CodeProject
if (type == CellType.NUMBER) {
}
}
}
} catch (BiffException e) {
e.printStackTrace();
}
return friends;
}
}

History
23rd March, 2019: Initial version

License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author


Hussein_HazimehNo Biography provided
Instructor / Trainer
Switzerland

Comments and Discussions


0 messages have been posted for this article Visit https://www.codeproject.com/Articles/1280631/How-To-Detect-Who-
Unfriended-You-on-Facebook to post and view comments on this article, or click here to get a print view with messages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile Article Copyright 2019 by Hussein_Hazimeh
Web05 | 2.8.190306.1 | Last Updated 25 Mar 2019 Everything else Copyright © CodeProject, 1999-2019

https://www.codeproject.com/Articles/1280631/How-To-Detect-Who-Unfriended-You-on-Facebook?display=Print 3/3

Vous aimerez peut-être aussi