现在的位置: 首页 > 综合 > 正文

Facebook使用应用登陆成功后回调返回认证失败解决方法

2013年01月14日 ⁄ 综合 ⁄ 共 1489字 ⁄ 字号 评论关闭

使用facebook的SSO进行登陆认证时,从应用中调用浏览器登陆的方式可以成功回调并且获得用户信息,但是当我们的应用打开了facebook程序进行认证时,确认画面顶部显示:

xxxApp is misconfigured for Facebook login.Press Okay to go back to the application without connecting to Facebook.

点击Okay后回调我们的应用时,会返回这样的错误信息:
com.facebook.android.FacebookError: invalid_key: Android key mismatch. Your key "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" does not match the allowed keys specified in your application settings. Check your application settings at http://www.facebook.com/developers

这时候需要这样做:
1.登陆:https://developers.facebook.com/apps
2.选择:Edit Settings
3.选择:Native Android App Publish from my Android app to Facebook.
在Key Hashes:中添加提示的key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,保存后即可验证成功

补充一下:

两种方式可以获取到debug的 hash key

1.

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

2.

   // Add code to print out the key hash

        try {

            PackageInfo info = getPackageManager().getPackageInfo(

                    "com.facebook.samples.hellofacebook"

                    PackageManager.GET_SIGNATURES);

            for (android.content.pm.Signature signature : info.signatures) {

                MessageDigest md = MessageDigest.getInstance("SHA");

                md.update(signature.toByteArray());

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

                }

        } catch (NameNotFoundException e) {

        } catch (NoSuchAlgorithmException e) {

        }

需要注意一点的是,生成keystore时,如果有-alias xxx参数,如:keytool -genkey -v -keystore mykeystore.keystore -alias mykeystore -keyalg RSA -keysize 2048 -validity 10000
那么在生成hash key时 就要加该参数,否则不能加,要对应好。虽然加了也不会报错,也能生成hash key 但是这个key是不对的,无法通过facebook的验证。

抱歉!评论已关闭.