Corona SDK: Customizing the Facebook Share Dialog using dynamic meta tags

This may be obvious for some, but it took me some digging and I figured I would share what I learned in a nice, easy to digest format.

Facebook documentation recommends the share dialog over the feed dialog for mobile developers. It’s supposed to be the easiest way to share stuff from your app. It doesn’t seem to be documented, but Corona supports the share dialog.

Feed allows you to pass in a name, caption, description, and a link to customize your dialog. Share on the other hand, only takes an href parameter — this is the url for your page. When you activate the share dialog, Facebook scrapes your page looking for specific meta tags to fill in the content.

Normally these meta tags are static, but if you want to take your sharing to the next level, you can dynamically generate them using a bit of server side code.

Note: The following assumes you have facebook configured with your app and that you have access to a server running php.

First, let’s look at the Lua code for Corona:

Notice that we are encoding a score and level Id into the url. Pretty simple so far!

Next, let’s look at the contents of share.php:

And that’s all it takes! Facebook has a nifty tool to verify that your meta tags are being read properly. You can check it out here. Simply enter your href with some sample values to see the results.

Example:

You may be wondering why you should go through all the trouble to use Share instead of Feed. The main advantage is that you can update your meta tag content on your server, and have it propagate to all versions of your app immediately instead of building and pushing out an update just to change one or two dialog properties.

Hopefully this helps a few of you!

Leave a Reply

Your email address will not be published. Required fields are marked *