Friday, June 01, 2012

Android ~ Facebook login issue from Android application

When developing android applications that uses Facebook’s LoginButton to authenticate and authroize, there will be no issues running on the emulator. But when the same apk file (android installation file) is installed in an android device and executed it won’t work. The Facebook’s LoginButton, after clicking, progresses a while and returns back to the same screen taking us nowhere.

There could be several reasons for this behaviour but I have came across a couple of symptoms and was successful in addressing those:

1.       You might have not set the hashkey for your application in facebook or you might have messed up/changed your working android debug.keystore file locally in your system.

If you have not yet set the hashkey for your application, please generate hashkey for your application first, then set the hashkey for the facebook application. Here is the article that explains in a step by step manner to create your hashkey: http://hemant-vikram.blogspot.in/2012/05/generating-hashkey-for-android-facebook.html

At times when working with our android application we may sometimes use other’s debug.keystore file and replace our’s to see if some of our issues go away. Now if we generate the apk file and install in the device to test it out, we will notice this issue. To resolve we will have to re-generate hashkey and set that in the facebook apps.
2.       You might have missed the invocation of super method in the protected void onActivityResult(int requestCode, int resultCode, Intent data) method block

If you have missed, then add the following as the first line in your method block:
super.onActivityResult(requestCode, resultCode, data);

Edit: There is one another problem that I dealt with the signed apk file. I used the following steps to sign the apk file:
Right Click on the Project -> Android Tools -> Export Signed Application Package...
I provided the project name and clicked next and selected the keystore location path that has an empty space in it. Having generated the keystore file, signed apk file, generated the hashkey using the keystore file and setting it to facebook app settings page I was seeing that I was not able to get past the login screen. I was seeing a facebook progress dialog and after few seconds it disappears. I was running out of clues as what could be missing. Later along with my colleague, went thru the same process of generating the keystore and all that but this time without an empty space character in the path. We ran the apk file and tried the facebook signon and bingo. It worked!!!

Hope this helps you to resolve your problem and importantly save some time…

Happy Androiding

No comments: