Gathering Facebook Identities from Email

Looking at the announcement of the Facebook Graph API from Facebook F8 it seems like it will be a little easier to work with the Facebook system.

In Raindrop we already have some integration with Facebook in order to identify emails coming from the Facebook system and help you filter them out. But there is a lot more that can be done to help keep your email, Facebook, and other contacts in a cohesive form.

So here’s a quick code example written in Python to grab Facebook identities from emails sent by Facebook. This could be used to gather Facebook identities and then possibly merge those with twitter and email contacts.

First we need to import a couple things.

import email, json, urllib2

Then we’ll need to grab an email message.  I used Thunderbird to save a Facebook notification email message as an EML file locally, I called that file ‘facebook.eml’ as you can see below.

msg = email.message_from_file(open('facebook.eml'))

Now we have a parsed email message msg object and we want to look for the X-Facebook-Notify header in the email so we can extract what happened.

fb_notifiy = [tuple(t.strip().split("=")) for t in \
              msg.get('X-Facebook-Notify').split(";")]

The object fb_notify contains tuples of information about the type of notification.  Here is an example of an object you might see.

[('event_wall',),
 ('eid', '14102494623'),
 ('from', '21602578'),
 ('mailid', '12bf28cG149a112G63016bG21') ]

Using fb_notify we’ll do a really simple grab of the from attribute because that is what is going to be publicly available from the Facebook Graph.

from_identity = json.load(urllib2.urlopen("http://graph.facebook.com/%s" % fb_notify[2][1]))

Here’s an example from_identity object:

{u'first_name': u'Bryan',
 u'last_name': u'Clark',
 u'id': u'21602578',
 u'name': u'Bryan Clark' }

The from_identity can be used to more clearly identify who Facebook is sending this notification on behalf of and we could try merging this Facebook identity with other identities we already have in our contacts.

I saved all this code into this gist if you want to take a look at it in code only form with syntax highlighting.

4 responses to “Gathering Facebook Identities from Email

  1. I like your information about Facebook, I share it on MySpace and Facebook!

  2. HELLO PASTOR,

    GRACE TO YOU AND PEACE FROM GOD THE FATHER AND OUR LORD JESUS CHRIST. I PRAY THE ALMIGHTY GOD BY THE POWER OF THE HOLY SPIRIT REVEAL THIS TRUTH TO YOU IN JESUS NAME. THAT NAME OF JESUS AS I HAVE BELIEVED IS TOO GREAT FOR ME TO LIE. I WAS SAVED AS A SINNER AND I PROMISED TO BUILD A CHURCH FOR MY GOD SINCE I REPENTED AND I SAW THE MANIFESTATION OF THE HAND OF GOD UPON MY LIFE. I STARTED BUILDING THE HOUSE OF GOD AS I HAVE PROMISED, AND THE BUILDING HAS REACHED A REASONBLE HIGHT BUT RIGHT NOW I CANT PROCEED FURTHER, SINCE I LOST MY JOBI AM BASED IN SPAIN I WAS WORKING TO RAISE THIS PROJECT ALL ALONE BUT NOW MY WORK STOPED AS

    I AM NOT ASKING OF ANY FINANCIAL ASSISTANCE FROM YOU BUT AS THE ALMIGHTY GOD MINISTER TO YOUR SPIRIT HE KNOWS WHAT I WANT, HE WILL TELL YOU WHAT TO DO. …..” which was not made known to men in other generations as it has now been revealed by the Spirit to God’s holy apostles and prophets..”Eph.3:5

    I WILL BE GRATEFULL TO YOU TO HEAR FROM YOU SOON AS THE LORD LAY IN YOUR HEART TO SUPPORT ME. IF YOU CAN CALL ME WE SHALL TALK AS REGARDS TO HOW THE BUILDING IS GOING. AND WHATEVER PHOTO REQUIRED OF ME TO PRESENT I SHALL DO THAT.

    BLESS YOU.
    THANKS

    GODSPOWER.

    0034677710391

  3. I like you post about facebook. many people say to much on these social networking sites. it could hurt them in the long run. thanks

  4. when it comes to job market. potential employers can look into facebook and myspace to determine someone’s character.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

aboot

This is the blog personality of Bryan Clark. I'm a designer in a world of open source. This blog reflects mostly writing about Design, Open Source, Economics, Beer, Wine, and Dogs. There's more information about me on this site or you can contact me directly at clarkbw@gmail.com.

scategories