dmc-facebook API

Details of the API for dmc-facebook

This documentation is In Progress, but the methods and properties are all listed.

Table of Contents

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

DMC Facebook API

Properties

has_login

Indicator whether we have a valid Facebook login or not.

Type: boolean

main.lua

local Facebook = require 'dmc_facebook'
if Facebook.has_login then print("we are logged into Facebook") end

access_token

The app access token from Facebook, to be used for data calls.

Type: string (or nil)

This is a string if has_login is true, nil if false.

main.lua

local Facebook = require 'dmc_facebook'
print( Facebook.access_token )

Basic Methods

init( app_id, app_url [, params ] )

Initialize the Facebook singleton object.

Parameters

Name Value(s) Notes
app_id eg, '236229049738744' Application ID in the Facebook servers.
app_url eg, 'http://m.davidmccuskey.com' URL configured in Facebook servers.
params table of parameters an (optional) table of configuration parameters. The possible entries are in the next table.

Optional Parameters

Name Value(s) Notes
view_type one of Facebook.MOBILE_VIEW or Facebook.DESKTOP_VIEW Determines which login page to use at Facebook.com. Default is Facebook.MOBILE_VIEW
view_params eg, {x=10, y=10, w=200, h=200} This is a table with dimensions for webview used for login. by default the webview takes up the entire screen

Example

main.lua Simple

local Facebook = require 'dmc_facebook'

local APP_ID = '236229049738744'
local APP_URL = 'http://m.davidmccuskey.com'

Facebook:init( APP_ID, APP_URL )

main.lua Advanced

local Facebook = require 'dmc_facebook'

local APP_ID = '236229049738744'
local APP_URL = 'http://m.davidmccuskey.com'
local APP_TOKEN_URL = 'http://m.davidmccuskey.com/app_token.php'

local fb_options = {
    view_type=Facebook.MOBILE_VIEW,
    view_params={
        x=10, y=10, w=display.contentWidth-20, h=display.contentHeight-20
    },
    app_token_url = APP_TOKEN_URL
}

Facebook:init( APP_ID, APP_URL, params )

login( permissions [, params ] )

Login user to Facebook. This will both:

  • Authenticate the user (user/password) and
  • Ask user for all permissions

This should be called after Facebook:init().

Parameters

permissions is an array of Facebook-permission strings. By default the Facebook permission basic_info is added onto the list.

params is an (optional) table of configuration parameters. Here are the possible entries

Name Value(s) Notes
view_type one of Facebook.MOBILE_VIEW or Facebook.DESKTOP_VIEW Determines which login page to use at Facebook.com. Default is Facebook.MOBILE_VIEW
view_params eg, {x=10, y=10, w=200, h=200} This is a table with dimensions for webview used for login. by default the webview takes up the entire screen
app_token_url eg, a URL This URL should have a script which communicates to Facebook servers and returns back an Facebook Application Token

Example

main.lua

local Facebook = require 'dmc_facebook'

local APP_TOKEN_URL = 'http://m.davidmccuskey.com/app_token.php'
local perms = { 'publish_stream' }

local fb_options = {
    view_type=Facebook.MOBILE_VIEW,
    view_params={
        x=10, y=10, w=display.contentWidth-20, h=display.contentHeight-20
    },
    app_token_url = APP_TOKEN_URL
}

Facebook:login( perms, APP_URL, fb_options )

cancelLogin()

Description

Example

main.lua

local Facebook = require 'dmc_facebook'
Facebook:cancelLogin()

logout()

Description

Example

main.lua

local Facebook = require 'dmc_facebook'
Facebook:logout()

request( path [, method, params ] )

Generic Facebook Graph method. This can be used to make any call with Facebook Graph API.

Name Value(s) Notes
path eg 'me/friends' --
method eg, 'GET' 'GET' or 'POST', defaults to 'GET'
params {...params...} an (optional) table of configuration parameters. Used to supply parameters to the data call.

Helper Methods

These are to make interfacing with Facebook API a little easier. they are just wrappers for more basic API methods.

getPermissions( [ params ] )

Get this app's permissions granted by current user.

Parameters

Callback Event

Facebook.GET_PERMISSIONS

Name Value(s) Notes
params -- --
data -- --
is_error -- --

Example

main.lua

--== THIS IS AN INCOMPLETE, CONTRIVED EXAMPLE !!

local Facebook = require 'dmc_facebook'

local facebook_handler = function( event )
    if event.type == Facebook.GET_PERMISSIONS then
        -- process what comes back
    end
end

-- make the Facebook call
Facebook:getPermissions()

postMessage( text [, params] )

requires publish_stream permission

Callback Event

Facebook.POST_MESSAGE

Name Value(s) Notes
params -- --
data -- on succes, the data, on error, the error message
is_error boolean true on error

Example

main.lua

--== THIS IS AN INCOMPLETE, CONTRIVED EXAMPLE !!

local Facebook = require 'dmc_facebook'

local facebook_handler = function( event )
    if event.type == Facebook.POST_MESSAGE then
        -- process what comes back
    end
end

-- make the Facebook call
local msg = "Test message post @ " .. tostring( os.time() )
Facebook:postMessage( msg )

Post a link to the user's Facebook wall.

requires publish_stream permission

Parameters

Params

Name Value(s) Notes
actions -- actions for the link

Callback Event

Facebook.POST_LINK

Name Value(s) Notes
params -- --
data -- --
is_error -- --

Example

main.lua

--== THIS IS AN INCOMPLETE, CONTRIVED EXAMPLE !!

local Facebook = require 'dmc_facebook'

local facebook_handler = function( event )
    if event.type == Facebook.GET_PERMISSIONS then
        -- process what comes back
    end
end

-- make the Facebook call
Facebook:postLink()

DMC Library Configuration File

There are currently no entries for the DMC Library config file for the Facebook Module.