Here we are again, with another post dedicated to the progress being made in our prototype.
We successfully made the much desired connection with facebook, getting all those juicy events you’ve been attending and are planning to attend. There wasn’t much trouble with it, as the FB graph API is pretty well documented and straightforward to use, but there were some minor issues.
The most noticeable one was directly related to the PHP.ini definitions. Apparently, you have to add a line to your definitions file to make the php server include the openssl extension (extension=php_openssl.dll), which allows us to connect to https:// pages, which is required when interacting with the FB graph API.
In order to successfully establish a connection with facebook, and be able to get the information we’re looking for (events in our case) there a few steps that need to be taken.
First you need to create a facebook app, which doesn’t need to do anything, but provides you with an app ID an app secret which are required for authentication (http://developers.facebook.com/docs/authentication/).
Then you need to authenticate the user. In your server side php code you have to redirect the user to the FB login dialog, passing it the app ID and the URL you wish to redirect once the login is made. If the user is already logged into FB, then there will be a cookie stored in the system, which will skip the login dialog. If it is the user’s first time dealing with our app, he will be prompted with a new dialog asking for permission to access his information. By default, all apps only request basic publicly available info, like the name, profile pic, etc. In our case, we need a bit more info, so we need to add a scope parameter to the initial redirection, that will prompt the user to provide the added permission ( &scope=user_events,friends_events).
Once the user is logged in, and permission to access his information has been given, we are redirected to the provided URL (our server script), which gets called with a ‘code’ parameter, the authorization code, which allows you to proceed to app authentication. This is done by calling the graph API token endpoint, adding to the previous parameters the app secret and authorization code. Given all your parameters are valid, you get a page back which content is the so called, access token. You use this token in all the API calls you which to make, so in our case, it is used to fetch the user’s event info.
Fetching the user’s event info is a simple matter. All you do is call the event page of the currently authenticated user (https://graph.facebook.com/me/events) and pass it the access code as a parameter. This returns a page which content is a JSON file with all the user’s events.
Now all that remains to be done is interpreting the JSON file, as we need to filter the results to be those between certain dates defined by the user in our Layar front end. We also need to give it some thought as to which friends’ events we include, if any, but this will most probably be out of our initial prototype, as it would involve the complex task of deciding which friends are more relevant to a user (who are his/hers ‘best friends’), or which events are most likely to be of the user’s interest.