Getting Started with dmc-facebook

Get quickly up-and-running with dmc-facebook.

dmc-facebook is easy to setup and easy to use. It provides more functionality than the Facebook plugin provided by Corona Labs.

Table of Contents

{toc:style=disc|indent=20px|minLevel=2|exclude=Table of Contents|printable=false}

dmc-facebook Basics

Facebook App: Create

Create your Facebook app following the regular instructions. Here is a link to the developer dashboard:

https://developers.facebook.com/apps/

Facebook App: Settings

Here are some screenshots of the Facebook App center. Click thumbnail to expand.

Basic Screen

  • remember your App ID as you will need this when calling init(). This is APP_ID when configuring dmc-corona.

  • Sandbox Mode should be Disabled

  • the domain in App Domains and Mobile Web should be the same. This is APP_URL when configuring dmc_library.

FB Plugin Test

Permissions Screen

  • Change Auth Token Parameter to URI Fragment

FB Plugin Test

Now all of the setup is done on the side of Facebook, let's work on the app

dmc-facebook Plugin Setup

The following code is all that's required to use dmc-facebook. Copy and paste into main.lua. Be sure to include

DMC Facebook Basic Example

--===================================================================--
--== Imports


local Facebook = require 'dmc_facebook'


--====================================================================--
--== Setup, Constants


-- USE *YOUR* FACEBOOK APPLICATION INFO FOR THESE SETTINGS !!
--
local APP_ID = '236229049738744'
local APP_URL = 'http://m.davidmccuskey.com'


--===================================================================--
-- Main
--===================================================================--


local facebook_handler = function( event )

    if event.type == Facebook.LOGIN then
        print( "--== We are now logged in" )
        print( "\n" )

        -- get some data
        Facebook:request( 'me' )

    elseif event.type == Facebook.REQUEST then
        print( "--== Request() data response" )

        -- output results
        local data = event.data
        print( "Name: ", data.name, data.last_name )
        print( "Username: ", data.username )
        print( "User URL: ", data.link )
        print( "\n" )

        -- now logout
        Facebook:logout()

    elseif event.type == Facebook.LOGOUT then
        print( "--== We are now logged out" )
    end

end

-- initialize facebook plugin
Facebook:init( APP_ID, APP_URL )
Facebook:addEventListener( Facebook.EVENT, facebook_handler )

-- login to facebook, 'basic_info' is default perms
Facebook:login()

In such a little bit of code we have accomplished a lot! But there is so much more waiting. Check out some of the other documentation.