Tuesday 26 February 2013

Android facebook SDK throwing exception : remote_app_id does not match stored id




Recently I was trying to make Facebook SDK integrated with the native android app. It was quite tricky to get it working and you may come across this exception:

ApiException:  remote_app_id does not match stored id






  • First thing you will need to do is to put the KeyHash in your App configuration in your Facebook developer dashboard.

  • As showon here :
    To get the KeyHash from keytool:
    keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64
    
    it will ask for the password, type "android" (without quotes)

    Finally paste the generated hash code the your dashboard and click "save changes".


    • Sometimes the openssl installed on your computer may produce a different key hash code for your andoird application, and most likely it will throws ApiException :  remote_app_id does not match stored id . To resolve this check the hashcode generated from the code:

            try {
                PackageInfo info = getPackageManager().getPackageInfo(
                        "com.example.yourpackagename", 
                        PackageManager.GET_SIGNATURES);
                for (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) {
    
            }
    
    • Remember to use the correct package name as you put in your facebook app dashboard, you can also abtain it from the AndroidManifest.xml, "package=com.example.yourpackagename"
    open command prompt and type in "adb logcat" because the facebook exception may not be displayed in the IDE's logcat. Observe the KeyHash generated from the above code. It may be different from what you did by using keytool, copy and paste it to you dashboard, save the chages. Wait for the facebook to update its server and thats it! You should now be able to Login to facebook, calling APIs from you own app!

    No comments:

    Post a Comment