« My Mini Project Idea – Mapped Hostels | Main | Head Rush Ajax – Chapter 4 »

The Facebook API for our Project

Last Friday I had a “wonderful” night with the Facebook API. It took me some time and rage but I finally could extract some of my friends “attributes” onto my own page. I started by reading the documentation and obtaining a developer key. After some disappointing experiments I searched the developer forum for examples and found some helpful code snippets. Some hours later I could extract the keys of my friends, look them up and retrieve their “attributes”. Here is a short overview of the code:

home.php
If no authentication token is present it prompts the visitor to logon to Facebook.com. After a user has logged on, Facebook redirects him/her and the authentication token back to home.php.

beginSession.php
The authentication token is immediately used to establish a new session (key) which will be used for all further calls to Facebook API methods.

requestDetails.php
Right after a session key was obtained, the friends of the current user are requested. Each request needs the developer key, the session key, the call id (a consecutive number, used only once per session) the method name (in the first case facebook.friends.get) and a signature for exactly this request (which must be requested just before making this request). The facebook.friends.get method returns a XML file which needs to be parsed. Once all friends Ids were in an array I requested some details for each friend (facebook.users.getInfo) and displayed them on the PHP page.

Until now this all happens without any AJAX techniques involved but this will change soon.

200702070101

Comments (1)

Sounds like quite a bit of work and like you did a great job figuring out the api. I'd like to use this as an example today in class. My suspicion is that you might have been able to do this with ajax and a proxy. That's how I did the google base stuff.

That's not to say php is bad. It's just that I personally am trying to avoid server side programming.

Archives

Cool links

Blog Maintenance, EMUonline, Learningremix, Bud's Blog, Andre's Blog, Joern's Blog, Bud's Page, MYB-Tags, MYB-Joern, MYB-Andre, MYB-Thomas

Interesting stuff