facebook.showDialog()

Type Function
Library facebook.*
Return value Event
Revision Current Public Release (2014.2511)
Keywords facebook
See also Facebook Portal Setup
Implementing Facebook
facebook.login()
event.response
event.isError
event.didComplete

Overview

Displays a Facebook UI dialog for publishing posts to a user's stream using only a few lines of code.

This API is an easy way to add Facebook functionally to an application without the need to create a dialog box or handle the response.

Note: This API pops up a Facebook UI that the user interacts with. Use facebook.request() if you need the application to do the posting.

The response from the dialog comes back in the form of a fbconnect event that is sent to a listener. This listener was registered during the call to facebook.login().

Syntax

facebook.showDialog( action [, params ] )
action (required)

String. The dialog you want to show, for example "feed" or "apprequests". See this guide for more information.

params (optional)

Table. Lua table of key/value pairs that's passed as arguments to the Facebook API call. The keys you pass here correspond to specific options that are available for the dialog you want to show. See this guide for more information. The individual dialog reference pages list the available options for the dialog.

Facebook Places

facebook.showDialog() can be used to display a native view controller, allowing the user to choose a place where they are.

facebook.showDialog( action, options, onComplete )
action (required)

String. The dialog you want to show. For the place picker, you should pass "place".

options (required)

Table. This is a Lua table of key/value pairs that are passed as arguments to the Facebook API call. Supported keys are:

  • options.title — string value for the title that will appear in the view controller's navigation bar (top of the screen).
  • options.searchText — string value for the type of place you wish to search for. i.e. "restaurant", "hospital", "supermarket", etc.
  • options.longitude — numerical value for the longitude value of the place.
  • options.latitude — numerical value for the latitude value of the place.
  • options.resultsLimit — number representing the maximum number of results shown in the view controller.
  • options.radiusInMeters — numerical value for the radius in meters that the search should span.
onComplete (required)

Listener. This listener is executed upon selecting a place.

Facebook Friends

Displays a native view controller, allowing the user to choose who they are with.

facebook.showDialog( action, onComplete )
action (required)

String. The dialog you want to show. For the friend picker, you should pass "friends".

onComplete (required)

Listener. This listener is executed upon selecting a friend.

Gotchas

Please see the Implementing Facebook guide for important iOS and Android-specific notes.

Examples

local facebook = require( "facebook" )

-- listener for "fbconnect" events
local function listener( event )
    if ( "session" == event.type ) then
        -- upon successful login, request list of friends
        if ( "login" == event.phase ) then
            facebook.showDialog( "apprequests", { message="You should download this game!" } )
        end
    elseif ( "dialog" == event.type ) then
        print( event.response )
    end
end

-- first argument is the app id that you get from Facebook
facebook.login( "XXXXXXXXXX", listener )  --replace XXXXXXXXXX with your Facebook App ID
Places/Friends
local facebook = require( "facebook" )

local function onComplete( event )
    print( "event.name:", event.name )
    print( "event.type:", event.type )

    if ( event.data ) then
        print( "{" )

        for k, v in pairs( event.data ) do
            print( k, ":", v )
        end

        print( "}" )
    end
end

-- Show the place picker
facebook.showDialog( "place", { title="Select A Restaurant", longitude=48.857875, latitude=2.294635, searchText="restaurant", resultsLimit=20, radiusInMeters=2000 }, onComplete )

-- Show the friends picker
facebook.showDialog( "friends", onComplete )