O'Reilly logo

Programming Collective Intelligence by Toby Segaran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Matching on Facebook

Facebook is a popular social networking site that was originally for college students but eventually opened up to a larger audience. Like other social networking sites, it allows users to make profiles, enter demographic information about themselves, and connect to their friends on the site. Facebook also includes an API that lets you query information about people and find out if two people are friends or not. By doing this, you can build a set similar to the matchmaker dataset using real people.

As of this writing, Facebook has remained very committed to privacy, so you can only view the profiles of people who are your friends. The API applies the same rules, requiring a user to log in and only allowing queries, so unfortunately, you'll only be able to work through this section if you have a Facebook account and have connected to at least 20 people.

Getting a Developer Key

If you have a Facebook account, you can sign up for a developer key on the Facebook developer site at http://developers.facebook.com.

You'll get two strings, an API key and a "secret" key. The API key is used to identify you, and the secret key is used to encrypt your requests in the hash function that you'll see later. To start, create a new file called facebook.py, import some modules you'll need, and set up some constants:

import urllib,md5,webbrowser,time
from xml.dom.minidom import parseString
apikey="Your API Key"
secret="Your Secret Key" FacebookSecureURL = "https://api.facebook.com/restserver.php" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required