Facebook Graph API <--> iOS [Integration Notes]

I had the opportunity to work on an iPhone app that was used in the Les Filles et Les Sciences (2012) conference/workshop. Specifically, I worked on the Facebook integration part; allowing the users of the app to post a new photo on their Facebook accounts (the photo they have taken with the iPad).

During the process, I have learned that Facebook has switched to a new API called Graph API and the old REST API would soon be obsolete. So, Graph API was the way to go to make sure that the app works in the future.

Overall, it was a very straightforward process. Briefly, here were to steps:

1. Create a new Facebook app (not to be confused with the iPhone app). The Facebook app is your handle when interacting with Facebook. This interaction is well-illustrated here:


2. Download and use the official Facebook iOS SDK .

3. Make use of the 3 main protocols (interfaces, as the Java world would put it) when performing your integration from your iPhone app:
- FBSessionDelegate: Handle logging-in, authorization
- FBDialogDelegate: Handle users' interaction with Facebook
- FBRequestDelegate: Handle requests (POST,GET,DELETE) to Facebook

Though it depends on your Objective-C skills and iOS experience, it should only take few hours to get the happy scenario working.

Further enhancements

As with any software specification in the industry, the happy scenario wasn't enough for this app. There were 2 "custom" features proved to be necessary when implementing the integration:


  • The user shouldn't leave the app at all (i.e. no switching to another app via fast app-switching) to login to Facebook [the app should be as simple as possible; the users would be confused if switching occurs]
  • The user has to enter his/her credentials every time s/he connects to Facebook [the same device will be used by many users; users shouldn't access each other's accounts]

    Here is how the enhancements were carried out:
  • The default behaviour of the Facebook iOS SDK is to perform the authentication in either the Facebook app (if installed) or in the Safari app. This had to be changed so that the users never leave our app. After analyzing the iOS Facebook SDK and StackOverflowing a little bit, that was resolved. Here is how.

  • With the default functionality of the Facebook iOS SDK, you would store user's credentials in the form of cookies (not using single-sign on). The requirement indicates no saving of credentials, so I have decided to delete the cookies when connecting to Facebook. Here is the method for that:

    - (void) deleteCookies {
     NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
     
     for( NSHTTPCookie *cookie in [cookieJar cookies]){
      [cookieJar deleteCookie:cookie];
     }
    }
    

    So, overall it was very good to get to know a little bit about the Facebook Graph API. I think the API is well documented and it is easy use. Same things can be said for the iOS SDK.

    [By the way, during this project, I have found out something cool: http://facebook.stackoverflow.com/; a collaboration of Facebook and StackOverflow]
  • Comments

    1. I couldn't refrain from commenting. Perfectly written!
      Also see my site :: facebook ipo

      ReplyDelete

    Post a Comment

    Popular Posts