Friday, August 26, 2011

Facebook integration with Android and PhoneGap

Part of my current project involves posting to Facebook when a user completes an action.  Conveniently there's a plugin and an excellent article on how to use it  Unfortunately, when I tried to call the authorize function, I found that the Facebook page would load, and then quickly close without performing the authorization.  Looking at the console output in DDMS showed that the error was :Login Failed:  invalid_key.

When you create an android application that integrates with Facebook, you need to tell Facebook what your application key is using the following statement:

keytool -exportcert -alias androiddebugkey \
        -keystore ~/.android/debug.keystore | openssl sha1 -binary \
| openssl base64

Great.  Unfortunately what I wasn't aware of was that if you use the wrong password when prompted, the keytool silently returns a garbage string that is NOT your key.  Thanks to some quick research on stackOverflow and I found that the default password for the keystore is 'android'.  Providing the correct key to Facebook allowed the plugin to correctly authorize me.  Hopefully, this will be helpful to someone else!

1 comment: