Sunday, July 31, 2011

Facebook implementation into android

There has been a lot of tutorials about social sites and its implementations into Android. Most of these tutorials are very well written and fairly simple. Facebook in particular came up with a brilliantly yet easy to implement sdk and the documentation that comes with it is also good.

About six months ago, i was working on an application that needed me to implement FB, and while doing so i came up with a strange problem. My facebook login dialog disappeared soon after loading. After banging my head for some time and goggling i came across something called an SSO in facebook. 



This mainly happens because there are more than one facebook implementation in your phone. i mean you might have the usual FB application in which you have already signed in, and one you are presently working on.

According to FB "one of the most compelling features of the Android SDK is Single-Sign-On (SSO). SSO lets users sign into your app using their Facebook identity. If they are already signed into the Facebook Android app on their device they do not have to even type a username and password. Further, because they are signing to your app with their Facebook identity, you will have access to their profile information and social graph."


Since you have already signed in the FB application, when you try to implement FB in your application the SSO feature would sign you in straightaway and therefore the login dialog box disappear almost immediately after it first appears. There are however ways in which you can FB that this is a different application and you need me to ask to sign in again.


1.  by forcing the login dialog rather than SSO by passing FORCE_DIALOG_AUTH in the authorize methods in Facebook.java.


2. This method is quite complicated and involves a lot of steps. there is a brilliant blog dealing with this method therefore i might as well save myself some time and provide a link to this bolg. http://sean.lyn.ch/2011/07/android-the-facebook-sdk-sso-and-you/

3. The third way is very simple and effective. It tackles the problem stated in step 2, but in a very easy way. Just replace the package name "com.facebook.katana" to your own application package name in the file Facebook.java. Also replace the class name "com.facebook.katana.ProxyAuth" to "your-package-name.ProxyAuth" and see for yourself if you are good to go.