1

I have an issue with SSO using the Facebook SDK for Android. The problem occurs only when the native Facebook application is installed. When it's not installed, everything works fine, specifically:

Facebook facebook = new Facebook(APP_ID);
facebook.authorize(mActivity, , new DialogListener() {
   ...
});

facebook.isSessionValid(); // returns true

But when the native application is installed, facebook.isSessionValid() still returns false despite the fact that I called the authorize method.

I should add that I created an native Android based Facebook application with the hashkey generated from my debug certificate using keytool.

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

What is going on?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
  • same here. did you happen to solve this? – Lior Iluz Jan 29 '12 at 15:49
  • Tested on 4.0.3 and 2.3.4. I have created a bug report here http://developers.facebook.com/bugs/166465130126268 but apparently they say it should work. Need to read the documentation again and find what is causing the issue. – Amokrane Chentir Jan 31 '12 at 10:42
  • See here: http://stackoverflow.com/questions/4489791/facebook-android-sdk-invalid-key/4496457#4496457 and here: http://sean.lyn.ch/2011/07/android-the-facebook-sdk-sso-and-you/ . I got the same Login failed: invalid_key error in my logcat, so these may provide the right solution. – Lior Iluz Jan 31 '12 at 10:44

2 Answers2

7

SOLVED! :)

I sure hope this will work for you as well. The problem is that Windows generates an invalid key.

Run this with your app:

try {
   PackageInfo info = getPackageManager().getPackageInfo("**YOURPACKAGENAME**", PackageManager.GET_SIGNATURES);
   for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.i("PXR", Base64.encodeBytes(md.digest()));
   }
}
catch (NameNotFoundException e) {}
catch (NoSuchAlgorithmException e) {}

Don't forget to get Base64 (http://iharder.sourceforge.net/current/java/base64/).

The generated key is on your logcat, replace the old one with this.

Solution thanks to: http://p-xr.com/implementing-facebook-into-your-app-invalid-key-with-keytool/

Lior Iluz
  • 26,213
  • 16
  • 65
  • 114
0

In addition to what Lior wrote

you can do the log like this:

Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));

so you can use Andorid Base64

ref: Invalid Key Hash Troubleshooting

Tzahie Leibovich
  • 131
  • 3
  • 10