The Corona Labs Blog
Posted on . Written by

Frequently Asked QuestionsIt’s Wednesday and time for another FAQ session. Here are five frequently asked questions (FAQ)

1. What is the proper way to use Facebook.showDialog?

The showDialog API brings up a dialog screen where the user can enter a message about what is about to be sent/posted. This API now requires an “action” parameter. This parameter can either be “feed” or “apprequests”. If apprequests is used, there also must be a “message” parameter supplied or it will fail. Here is an example:

facebook.showDialog( "apprequests", {
message = "Example message."
} )

2. The Single Sign On (SSO) for iOS is not working. What can cause this?

Your app needs to set UIApplicationExitsOnSuspend key in the build.settings file to false. This is the default state but some users included this key and set it to true and that will cause the SSO to fail.

You also need to include your Facebook App ID in the build.settings file. See Jonathan’s blog post about how to do this.

3. My users are having to re-logon every few hours into Facebook from my app. Is there anything I can do to extend the time?

Yes, you can enable “Remove offline_access permission” in the Facebook app set-up page. Go to https://developers.facebook.com/apps/ and click the “Edit App” button at the top right corner of the page. Now click on “Advanced” under the Settings menu. You should see the following screen. Make sure “Remove offline_access permission” is Enabled. That should extend the logon token for 60 days.

Facebook Setup Extend Token

4. How can I tell when the Facebook token will expire?

The Corona Facebook API listener returns the token expiration time in event.expiration when event.phase == “login”. The following code will display the number of days until it expires.

print( ">>> Token expires in " ..
os.difftime( event.expiration, os.time() )/86400 .." days" )

5. I’m getting a log-on error when I enable Facebook’s Single Sign On (SSO) for Android. How do I generate the “Android Key Hash?”

If you have Single Sign On (SSO) enabled in your Android app, you may have had it fail because you didn’t supply the correct hash key. You will see a message like this in ADB logcat when you tried to logon: “invalid_key:Android key mismatch. Your key “PGv8R2vDQ/w6hexLxdefWKxcYLS” does not match the allowed keys specified in your application settings. Check your application settings at http://www.facebook. … “

You could use ADB to figure out what your key should be but this is easier: just copy and paste the key string displayed in the logcat terminal window into your Facebook app page where it asks for the Android Key Hash. If you type in “123” (as a place holder) and run your app, it will display the correct hash key in the logcat output.

Go to https://developers.facebook.com/apps/ and click the “Edit App” button at the top right corner of the page. You will be on the “Basic” page where you will find the Android SSO settings.

Facebook Android SSO

Note: If there is an older Facebook app on the device that doesn’t support SSO, the log-in call will bring up a local web popup instead of calling the Facebook app. In this case the hash key is not used.

Also, if the user upgrades their Facebook app to one that supports SSO, they will need to log out from your app or the token will be incorrect and any request/dialog API calls will fail because of an invalid token. (Corona saves the token from the last successful login and uses that for all API calls.)

That’s it for today’s questions. I hope you enjoyed it and even learned a few things.

9 Responses to “FAQ Wednesday: Your Facebook Questions”

  1. Gregory

    Awesome stuff! I love the FAQ.

    Maybe a dumb question, but do you need to enable facebook SSO to allow a simple message post using the facebook.showDialog() ?

    Reply
  2. thegdog

    Agree, great post. It would be great if showDialog() actually had a good example users could reference. I am having issues with NSURL error on the first showDialog() call over cellular that seems random, and there isn’t enough documentation on the function to help me find out how to capture or prevent the error.

    Reply
  3. eng_dev

    i didn’t use native android app, i use corona sdk ,so it’s possible to share a photo on Facebook wall from my android app game or not ???

    Reply
  4. mehad

    what a bout post audio file on face book ?? can I do that ,and if i can’t how I share sounds with friends on any social sites

    Reply
  5. Areej

    plz i wanna ask about inviting friends on facebook , i tired in this but all my tries failed , if i have a button to invite my friends on facebook to play my game how can i do this

    Reply
  6. thegdog

    So I just ported one of my apps over to Android from the iOS version which has been running great.

    I am having trouble , though, getting the Facebook Hash key.

    I added a Native Android app in the developer section on Facebook, putting “123″ in for the hash key for the time being. I put “com.ansca.corona.CoronaActivity” in for the Class name. I am running adb logcat and I have an Android tablet connected. The Terminal window is getting data from the tablet.

    I launch my app on the tablet and click the Facebook button. On the tablet, it opens the Facebook window and says the app “is misconfigured for Facebook login. Press Okay to go back to the application without connecting it to Facebook.”

    Looking in the Terminal window, there is no reference to the Facebook hash key. Does this error indicate something different than a hash key mismatch? Or is this method of getting the hash key no longer valid?

    Reply

Leave a Reply

  • (Will Not Be Published)