Skip to content

Check who Unfriended you on Facebook with Codeception

Facebook does not want to tell you who unfriended you. There are some mobile apps and internet services available which seem to check that for you, but I do not want send my Facebook data to some third party.

Since I work a lot recently with Codeception I had the idea to simply read all the listed friends directly from the Facebook website via the Selenium Webdriver (instead of using some API). And it seems to work quite well.

What it does (of course, automatically):

  1. login to Facebook
  2. go to your Facebook friends page
  3. scroll down until all friends are shown
  4. collect all friend names from the website
  5. compare the list with the one you saved before

Here comes the code doing this:

<?php

class checkFacebookFriendsCest {

    private $myOldFriends;
    private $firstTime = false;

    public function _before(AcceptanceTester $I) {

        // read the last list of friends, if exists
        try {
            $this->myOldFriends = json_decode(
                    file_get_contents("facebookFriends.json"), true);
            \Codeception\Util\Debug::debug('Last time I found ' .
                    count($this->myOldFriends) . ' friends.');
        } catch (Exception $e) {
            \Codeception\Util\Debug::debug('Found no friends file. Will '
                    . 'create one.');
            $this->firstTime = True;
        }

        // login to Facebook
        $I->amOnPage('/');
        $I->fillField('E-Mail-Adresse oder Handynummer', 'your@mail.xxx');
        $I->fillField('Passwort', 'yourPassword');
        $I->click('Anmelden');
    }

    // tests
    public function checkFacebookFriends(AcceptanceTester $I) {
        $I->amOnPage('yourFacebookID/friends');
        $I->wait(4);

        // unless we see "Mehr über" we scroll down to see all friends
        while (true) {
            try {
                $I->see('Mehr über', 'h3');
                break;
            } catch (Exception $e) {
                $I->executeJS('window.scrollTo(0,document.body.scrollHeight);');
            }
        }

        //  count all friends
        $myFriends = $I->grabMultiple(['xpath' => "//a[contains(@data-gt,"
            . " 'engagement')]"]);

        \Codeception\Util\Debug::debug('I found ' . count($myFriends) .
                ' friends.');

        // save new friends list
        file_put_contents("facebookFriends.json", json_encode($myFriends));

        if ($this->firstTime)
            return;

        // show result
        if ($this->myOldFriends === array_intersect($this->myOldFriends,
                $myFriends) && $myFriends === array_intersect($myFriends,
                        $this->myOldFriends)) {
            \Codeception\Util\Debug::debug('No Changes!');
        } else {
            $diff = array_diff($this->myOldFriends, $myFriends);
            if (!empty($diff)) {
                \Codeception\Util\Debug::debug("You lost these friends:\n");
                \Codeception\Util\Debug::debug($diff);
            }
            $diff = array_diff($myFriends, $this->myOldFriends);
            if (!empty($diff)) {
                \Codeception\Util\Debug::debug("You won these friends:\n");
                \Codeception\Util\Debug::debug($diff);
            }
        }
    }
}

Note that you need to adapt a few things:

  1. your email
  2. your password
  3. your FacebookID in the link to the Friends page

Also, when you are not using the German Facebook page:

  1. the name of the login label for the username
  2. the name of the login label for the password
  3. the name of the text which indicates that all friends are loaded (currently “Mehr über”)

  • Twitter
  • Bookmark Check who Unfriended you on Facebook with Codeception at del.icio.us
  • Facebook
  • Google Bookmarks
  • Digg Check who Unfriended you on Facebook with Codeception
  • Identi.ca

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Gravatar, Twitter author images supported.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
Form options