Facebook 101 for Android debug build

Hey Folks, I just spent a few days trying to get the Corona Facebook sample app (Scrumptious) up and running and I thought I would share a few lessons learned- I was successful, yay!  I know you can find all of this in bits and pieces throughout the coronalabs web site, but I will try to pull it all together and make some corrections/clarifications.

Hopefully this will save some of you time.  Also, if you are more experienced and you see some error here, please let me know.

But before we get started, just wanted to share some of my setup info, so you can see whether this applies directly to you.  I’m using Windows 7 and Corona SDK build 2013.2100 (currently the latest public build).   My phone is a Samsung S3 with Android version 4.3 (make sure you upgrade your Android SDK Platform Tools to 1.0.31 if you just upgraded to 4.3).   Also, I do have the latest version of the native Facebook app installed on S3.

  1. Copy the Corona Scrumptious samples app (found under Networking) to a new folder (always good to have something to fall back on).

  2. Go to https://developers.facebook.com/apps to register as a developer and create a new app.  Enter your display name, email and enable Sandbox mode (optional, but I recommend it).   Click on (select) Native Android App.  Enter your package name (just like you did in the Corona Simulator when you went to Build your apk file and enter this for your class name:

com.ansca.corona.CoronaActivity

  1. The next part (key hashes) was rather tricky for me because there was a fair amount of uncertainty from the instructions I read, but I will try to provide you with some certainty here:

a) Download and install openssl from here: 

https://code.google.com/p/openssl-for-windows/downloads/list

If you are using 64 bit windows, then use the 64 bit version.  I’ve also seen it recommended to use this version even though it’s not the latest (and this worked for me):

https://code.google.com/p/openssl-for-windows/downloads/detail?name=openssl-0.9.8e_X64.zip&can=2&q=

b) Place the openssl folders anywhere you like, but you will need to use their path in a minute

c) Find your Corona Labs debug.keystore, I found mine here: 

C:\Program Files (x86)\Corona Labs\Corona SDK\Resources

d) Find your Java keytool.exe, I found mine here:

C:\Program Files (x86)\Java\jre7\bin (I believe that jre6 will work, but jre7 definitely did)

e) Open a CMD window and cd (change directory) to the Corona Resources folder, then run this command line (all one line):

keytool -exportcert -alias androiddebugkey -keystore debug.keystore | “C:\Program Files (x86)\openssl\bin\openssl.exe” sha1 -binary | “C:\Program Files (x86)\openssl\bin\openssl.exe” base64

Replace my path to openssl with yours.  IMPORTANT: You will be prompted for a password, use android as the password.

f) The result you get will be the key hash you need for Facebook.   Copy the whole thing (mine had an equal sign at the end).  If you have an equal sign at the end, then you definitely need it.  The whole key hash should be 28 characters in length (including equal sign).  Paste this sucker where it says Key Hashes in the Facebook Developer portal in the Native Android app section.  

  1. Select Facebook Login enabled and Deep Linking enabled.  

  2. Save changes in the Facebook Developer portal.  It should say that this may take some time to propagate to all the servers, so we can do a few other things now.

  3. Copy the Facebook app ID.  If you are prompted to enter app details, you only have to enter some and you do NOT have to click on “Submit App Detail Page.”   If you must, enter Display Name, Tagline, Description, Detailed Description, Category and User Support Email then submit changes.

  4. Open the Corona Simulator (again, I used public build 2100) and your text editor.  Open up the build.settings file and replace the X’s with your new Facebook app ID.  There are two places where you must do this and they are commented.

  5. Open up the loginScreen.lua file and replace the X’s with your Facebook App ID near the top of the file.  Remember, the app ID needs to be a string, so include double quotes around the app ID.  I forgot to do this and that is one of the major reasons I’m writing this for you (cost me about 8 hours of time!).   You do not need to enter anything for fbCommand (leave it as nil).  You do NOT need to use your Facebook app secret (even though the comments indicate you do).  

  6. Open up mainScreen.lua and paste your Facebook app ID there to replace nil near the top of the file.  Again, remember to use double quotes surrounding the app ID.  Again, you do NOT need to provide the Facebook app secret.  Search for “corona_scrumptious:eat” and replace with “feed”.  If  you don’t do this, your post will not show up.  I’m sure someone had some intention for the alternative text, but I could not figure it out and posts were not showing up.

  7. Go to the Corona Simulator and Build for Android.  Browse to where the Corona debug.keystore is located (for me: C:\Program Files (x86)\Corona Labs\Corona SDK\Resources\debug.keystore).   Select the Alias Name as andoriddebugkey.  Make sure the package name matches whatever you put in the Facebook developer portal for your app.  

  8. After you build and install on your device, if you want to monitor things, here are a couple of options:

adb logcat Corona:V *:S     or

adb logcat       if you want to see a lot more info

If you need to be able to search through the log, then:

adb logcat > corona.txt works nicely

  1. After all that, I did get the scrumptious app to run.  It presented a login button and after it was pressed, it used my native Facebook app for authentication.  I then got the scrumptious menu, made my selections, submitted and the post showed up on Facebook.  Yay!   You might want to go into the mainScreen.lua file and update the latitude and longitude for the places lookup.  When you run the app, you do need to type into the textbox that appears if you want places to show up so you can choose one.

Whew!  That was a fun way to spend Christmas, but hopefully now you won’t have to spend all the time I did.  Happy Holidays!

Michael

Thanks Michael, this is a very useful post. I’ve set it all up and hit the login button, but I’m just get a spinning wheel at the moment. I’ll leave it overnight and see whether it’s a propagation problem.

I tried Scrumptious again today. Sometimes a spinning wheel and other times I get the popup for permissions to connect to FB, but it won’t actually connect. I’m using an Xperia Z with Android 4.2.x and still on the G1.0 version of Corona, so I’ll try it with a G2.0 build over the weekend.

It doesn’t give me the error message, so I know that the Facebook settings are all correct - your tute was really very helpful for this, as I tried back in June last year, picking out the info from loads of different places and I eventually gave up.

Hey AndyCWatson, I’m happy to help, but need more info.  As I said in my tutorial, there are a lot more details, but I didn’t want to make the thing 8 pages long and then have everything change in two weeks anyway.  So, you’re going to need to do some methodical troubleshooting.   Let me know which things you have tried that have actually worked.   

I would definitely consider going back through the steps and either double checking or re-doing each one.   Facebook app key reset/renew, openssl key hash, make sure that the Facebook app key is embedded in the right place in the .lua files, make sure your using the right format, if you want an objective opinion, post your code, provide some screen shots.  

Oh, here’s a big one, do you have the native Facebook app installed on your phone?   Make sure you’re using the latest version of the Scrumptious app from the Corona sample code.

In most worldy situations, doing the same thing over and over again and expecting different results is the definition of insanity.  In programming/IT, you must keep doing the same thing over and over again if you want to get different results!  IMHO…

Thanks Michael, this is a very useful post. I’ve set it all up and hit the login button, but I’m just get a spinning wheel at the moment. I’ll leave it overnight and see whether it’s a propagation problem.

I tried Scrumptious again today. Sometimes a spinning wheel and other times I get the popup for permissions to connect to FB, but it won’t actually connect. I’m using an Xperia Z with Android 4.2.x and still on the G1.0 version of Corona, so I’ll try it with a G2.0 build over the weekend.

It doesn’t give me the error message, so I know that the Facebook settings are all correct - your tute was really very helpful for this, as I tried back in June last year, picking out the info from loads of different places and I eventually gave up.

Hey AndyCWatson, I’m happy to help, but need more info.  As I said in my tutorial, there are a lot more details, but I didn’t want to make the thing 8 pages long and then have everything change in two weeks anyway.  So, you’re going to need to do some methodical troubleshooting.   Let me know which things you have tried that have actually worked.   

I would definitely consider going back through the steps and either double checking or re-doing each one.   Facebook app key reset/renew, openssl key hash, make sure that the Facebook app key is embedded in the right place in the .lua files, make sure your using the right format, if you want an objective opinion, post your code, provide some screen shots.  

Oh, here’s a big one, do you have the native Facebook app installed on your phone?   Make sure you’re using the latest version of the Scrumptious app from the Corona sample code.

In most worldy situations, doing the same thing over and over again and expecting different results is the definition of insanity.  In programming/IT, you must keep doing the same thing over and over again if you want to get different results!  IMHO…

I need help, my application only works for one user, in this case mine, but if I want to join with another, nothing happens, not hard, and not to do

I need help, my application only works for one user, in this case mine, but if I want to join with another, nothing happens, not hard, and not to do