安装Facebook本机应用程序时,isSessionValid()返回NO

安装Facebook本机应用程序时,isSessionValid()返回NO

问题描述:

我使用Android版Facebook SDK的SSO遇到问题.安装本机Facebook应用程序时,仅会发生此问题.未安装时,一切正常,特别是:

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

但是,在安装本机应用程序后,尽管我调用了authorize方法,但facebook.isSessionValid()仍然返回false.

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

我应该补充一点,我使用keytool从调试证书中生成的哈希密钥创建了一个基于Android的本地Facebook应用程序.

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

这是怎么回事?

已解决! :)

我当然希望这也会对您有用. 问题是Windows生成了无效的密钥.

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) {}

别忘了获取Base64( http://iharder.sourceforge.net/current /java/base64/).

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

生成的密钥在您的logcat上,用它替换旧密钥.

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

解决方案归功于: http://p-xr.com/在您的应用中将facebook实现为无效的密钥和keytool/