isSessionValid() returns NO when Facebook native application is installed

本秂侑毒 提交于 2019-12-06 16:07:15

问题


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?


回答1:


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/




回答2:


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



来源:https://stackoverflow.com/questions/8805843/issessionvalid-returns-no-when-facebook-native-application-is-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!