Facebook Login Flow on Android Broken Since Daily Build 1141

I am sooo happy to report that the case #25128 I filed has been addressed and the issue I described above is now fixed as of daily build 1179.  Yippee!  Thank you, Corona Labs Team!

Naomi

There may already be enough info here for everyone but I wanted to add in my experience with this problem to try and help the next person that runs into it.

I was getting two different kinds of errors that both stemmed from not having the key hash correct between my app and Facebook. If the Facebook app is installed on the device you have to have the key hash correct or your sign-on will fail. On older Android devices I was getting the ‘incorrect key hash’ error and on newer devices the Facebook app would return a ‘loginCancelled’ event to my app even when I accepted the facebook connection by hitting the ‘ok’ button. After looking at the logs I found that Facebook was throwing an error saying ‘remote_app_id does not match stored app_id’. All of these problems were resolved once I got my key hash configured correctly.

Correctly creating a keystore/key hash is a two step process. I had created a keystore several months ago on a different laptop and was trying to create the key hash for Facebook off that key. No matter what I tried it wasn’t working, until I went back and created a new keystore. 

So, if you’re still having issues like these try these steps. ( I’m posting steps for Mac OS X )

  1. In the terminal, move to the directory where you want to store your keystore file. Then create a new keystore for your application like this: ( where APP_NAME is your app’s name with no spaces)

    sudo keytool -genkey -v -keystore APP_NAME.keystore -alias APP_NAME_key -keyalg RSA -validity 999999

You will first be asked to enter YOUR USER PASSWORD. Then during the key generation process you’ll be asked for a new keystore password, remember it! You’re going to need it in the following steps.

  1. Once the keystore is generated you can now export the keyhash that you’ll need to give to Facebook.

    keytool -exportcert -alias APP_NAME_key -keystore APP_NAME.keystore | openssl sha1 -binary | openssl base64

You’ll need to enter the same password that you entered for your keystore. This command will spit out a long string, this is your key hash.

  1. Now you can log in to the Facebook developer console at http://developers.facebook.com and paste the key hash into the ‘Key Hashes’ box in the Native Android App section of the app settings.

  2. When you build your app for Android you’ll need to browse and select the newly created keystore file and select your key alias from the drop down menu. You will be asked to enter your keystore password again at this point.

Following these steps fixed the problems for me. My conclusion is that either the keystore is tied to the machine it was created on and therefore my hash was being exported incorrectly, or I had confused the password I used to generate my keystore and wasn’t entering the correct password when I tried to export the key hash.

I got this to work with Daily Build 2013.1234, I hope this helps someone else.

There may already be enough info here for everyone but I wanted to add in my experience with this problem to try and help the next person that runs into it.

I was getting two different kinds of errors that both stemmed from not having the key hash correct between my app and Facebook. If the Facebook app is installed on the device you have to have the key hash correct or your sign-on will fail. On older Android devices I was getting the ‘incorrect key hash’ error and on newer devices the Facebook app would return a ‘loginCancelled’ event to my app even when I accepted the facebook connection by hitting the ‘ok’ button. After looking at the logs I found that Facebook was throwing an error saying ‘remote_app_id does not match stored app_id’. All of these problems were resolved once I got my key hash configured correctly.

Correctly creating a keystore/key hash is a two step process. I had created a keystore several months ago on a different laptop and was trying to create the key hash for Facebook off that key. No matter what I tried it wasn’t working, until I went back and created a new keystore. 

So, if you’re still having issues like these try these steps. ( I’m posting steps for Mac OS X )

  1. In the terminal, move to the directory where you want to store your keystore file. Then create a new keystore for your application like this: ( where APP_NAME is your app’s name with no spaces)

    sudo keytool -genkey -v -keystore APP_NAME.keystore -alias APP_NAME_key -keyalg RSA -validity 999999

You will first be asked to enter YOUR USER PASSWORD. Then during the key generation process you’ll be asked for a new keystore password, remember it! You’re going to need it in the following steps.

  1. Once the keystore is generated you can now export the keyhash that you’ll need to give to Facebook.

    keytool -exportcert -alias APP_NAME_key -keystore APP_NAME.keystore | openssl sha1 -binary | openssl base64

You’ll need to enter the same password that you entered for your keystore. This command will spit out a long string, this is your key hash.

  1. Now you can log in to the Facebook developer console at http://developers.facebook.com and paste the key hash into the ‘Key Hashes’ box in the Native Android App section of the app settings.

  2. When you build your app for Android you’ll need to browse and select the newly created keystore file and select your key alias from the drop down menu. You will be asked to enter your keystore password again at this point.

Following these steps fixed the problems for me. My conclusion is that either the keystore is tied to the machine it was created on and therefore my hash was being exported incorrectly, or I had confused the password I used to generate my keystore and wasn’t entering the correct password when I tried to export the key hash.

I got this to work with Daily Build 2013.1234, I hope this helps someone else.