43

I'm trying to build a app that uses Facebook SDK for Android 3.0. But when I'm trying to call

Session.openActiveSession

It just simply gives me a SessionState with CLOSED_LOGIN_FAILED, and LogCat is:

12-16 00:03:40.510: W/fb4a:fb:OrcaServiceQueue(4105): com.facebook.orca.protocol.base.ApiException: remote_app_id does not match stored id 

I have searched StackOverflow with "remote_app_id" and the results are the "Bundle ID" in iOS, but I don't know what does the "remote_app_id" means in Android. I have already set the package name and the activity name in my Facebook app settings. I have no idea of the reason of the error.

David Fang
  • 1,717
  • 1
  • 14
  • 19
  • please MonkeyFish answer the actuall reason behind that is the Openssl please download the correct version,so that the hash key will be correctly generated – Muhammad Babar Apr 25 '13 at 10:42
  • **Note for 2014 -- this problem is the 'it works if the user does NOT have the fb app installed' problem. Note that >>> SOMETIMES <<< the solution is very simple; you have forgotten to put the right values on the developers.facebook site.** Brian from FB kindly explains here (note his images) http://answers.unity3d.com/questions/543540/facebook-sdk-v424-android-login-not-working.html Hope this helps someone, it's a real shitty problem if you get caught in it. – Fattie May 03 '14 at 15:03

7 Answers7

77

Another possible error (which happened with me) is: to set up a "Key Hash" at Facebook App Console and to sign the android app using another keystore.

Unfortunately this is caused because Facebook Getting Started Tutorial induces this error. It says that android developers should use default android debug key in your examples and doesn't explain that the Key Hash should be generated with the same keystore you will sign your application.

My recomendation is to set up two Key Hashes at your facebook console:

  1. default android debug key:

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

  1. your application release key:

keytool -exportcert -alias yourappreleasekeyalias -keystore ~/.your/path/release.keystore | openssl sha1 -binary | openssl base64

Remember: you cannot publish an application that is signed with the debug key generated by the SDK tools. So it isn't possible to publish an app using only the hash key generated using the first previous command line (as facebook tutorial suggests.

For more information about signing your application, visit Signing Your Application.

JPMagalhaes
  • 3,561
  • 1
  • 23
  • 26
  • 3
    Definitely this was the problem, as JPMagalhaes said, you should get both keys(Debug and Release) and post them into your Facebook Developers site. Afterwards, your debug and release APKs will work without problems. Don't forget to put the right aliases! :) – xarlymg89 Jan 24 '13 at 20:45
  • 2
    my problem was the same, the reason was different though: I checked out existing code from a co-developer; at FB login, I got the error above; resolution: make sure to add one debug key hash per development machine to your developer console (from the FB developers tutorial: "Note that you can add multiple key hashes here if you are developing with multiple machines.") – vaiomike Jan 26 '13 at 13:10
  • 3
    Much thanks to you JPMagalhaes, and shame on Facebook tutorials. – Faisal Apr 29 '13 at 09:15
  • @JPMagalhaes what is the path for release.keystore? – itamar May 24 '13 at 12:07
  • As you create it, it is expected you know where it is. Have you already created it? Normally I save it inside my project, so it is synchronized through all my computers. – JPMagalhaes May 24 '13 at 21:08
  • When generating your release key, you'll use something like: keytool -genkey -v -keystore [release].keystore -alias [yourappreleasekeyalias] -keyalg RSA -keysize 2048 -validity 10000 In this command, you have to define key's name and alias. The alias you define here, you use in the given command. For more information about signing your application, visit http://developer.android.com/tools/publishing/app-signing.html – JPMagalhaes Aug 06 '13 at 22:01
61

Another option is to print out the key hash sent to Facebook and use that value.

Make the following changes to the onCreate() method in your main activity:

try {
    PackageInfo info = getPackageManager().getPackageInfo(
          "com.facebook.samples.loginhowto", 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) {
}

Replace com.facebook.samples.loginhowto with your own package name.

This worked for me!

Michał Klimczak
  • 11,170
  • 7
  • 55
  • 92
TacoEater
  • 1,629
  • 15
  • 20
  • 3
    Tho things. 1) This comes from the [https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/](official doc), so yes it works. 2) The key to put in the app settings is the one you get from this code, not the one you get doing `keytool -list -v -keystore ~/.android/debug.keystore ......` – Stéphane Bruckert Mar 12 '13 at 16:16
  • Follow its error message, I expect that was an issue about facebook APP ID, but finally got true answer from here... – RRTW Jun 01 '13 at 09:56
  • For some odd reasons the key hash I get with `keytool -exportcert -alias -keystore | openssl sha1 -binary | openssl base64` doesn't work. I had to use this method to get the correct key hash – Fr4nz Jun 18 '13 at 12:07
  • 3
    Minor: There is one too many ending brace in your try statement – greg7gkb Jul 03 '13 at 17:50
  • Hi, I'm facing the same issue and my main activity is that of unity3d. The package name I enter in my Unity Build Settings is com.thisisit.finaltest. Should i enter this one or the one that is of unity's? Please do let me know about this. Cant even make a new key because an app has been signed with a key earlier (which produces a wrong keyhash) as it is on google play. – Siddharth-Verma Jan 27 '14 at 10:57
  • Perfect! THis was exactly that i was missing! missmatch between the hash generated by my app and the one that i had uploaded.! thanks again – Nitesh Verma Aug 12 '14 at 10:58
  • greg7gkb Nope, Count again ;-) – TacoEater Jan 24 '15 at 19:21
  • How would I go about doing this in phonegap? – DanceSC Oct 19 '15 at 18:23
34

I solved this question. The problem is, the "Key Hash" which I generated using "keytool" was wrong. When the "keytool" prompts for a password, you have to use "android" for it (without quotes). I was using my own password instead. When I changed my password, the problem just flew away. Hope this helps.

David Fang
  • 1,717
  • 1
  • 14
  • 19
  • 7
    Everyone should check out @JPMagalhaes answer as well. He is spot on about facebook forgetting to mention that you need to get the Key Hash on the production keystore you sign the app with. – KevinM Jan 02 '13 at 02:23
  • your mean that when typing password it should be a simple `android` ? i have use my `keystore password` it mean my own password. so again i have to create new Hash key? – Chintan Khetiya Mar 15 '13 at 04:45
  • @chintankhetiya except hash key for debugging , you need to add another hash key for release. I always generate wrong key with keytool, no matter enter the password of the keystore or "android". In the end I have to insert that snippets from MonkeyFish to get the workable key. So Weird. – Robert Aug 07 '13 at 02:17
5

I've got trapped by wrong openssl, that generated wrong hash key. i used openssl from http://gnuwin32.sourceforge.net/packages/openssl.htm that solved the problem.

user1892751
  • 51
  • 1
  • 2
4

I had the same problem, found out that the openssl was creating the wrong sha1. downloaded a new one and it worked like a charm.

TacoEater
  • 1,629
  • 15
  • 20
  • I used the print solution from above to find out that the encryption was wrong. – TacoEater Feb 16 '13 at 02:55
  • Thanks alot man, i wish i could +1000 on this one,dont know why this answer is not being selected the right one.....the Openssl was a big pain...Facebook should have a link to openssl in the sdk tutorial site – Muhammad Babar Apr 25 '13 at 10:39
0

Also, make sure that you enter the hash in the correct place in the facebook dev portal. Edit application settings and select Native Android App.

I had mistakenly put the hash in the 'Sample App Settings' instead.

zyked
  • 3
  • 1
0

You are getting the hash-key with debug key... Which may work if you haven't sign the package and running app in debug mode. What you need to do is :

1) Go to the manifest file and add to the application android:debuggable="true".

2) Now run your app and monitor the logcat.

3) You will get printed a new key which will be the matching key with x9SLcMXBlgly1f36PJuuc4a3YAc, The key you have got is now having a = sign in the last.

4) Register this key on facbook developer site

Alternate Trick

You can do one other thing Simply register this key to the facebook developers site x9SLcMXBlgly1f36PJuuc4a3YAc=

Just add = to the key which is being shown by the facebook app.

you are done!! Hope this will work.

MrDumb
  • 2,016
  • 1
  • 18
  • 30