facebook.showDialog()

Type Function
Library facebook.*
Return value Event
Revision 2017.3060
Keywords facebook
See also facebook.login()
fbconnect
Implementing Facebook

Overview

Displays a Facebook UI dialog for publishing posts to a user's stream. 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 as a fbconnect event that is sent to the listener function which was registered with the call to facebook.login().

Gotchas

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

Syntax

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

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

params (optional)

Table. Lua table of key-value pairs that is passed as arguments to the Facebook API call. The keys you pass here correspond to specific options which are available for the dialog that you want to show. See here for more information.

Facebook Places

Displays 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:

  • title — string value for the title that will appear in the view controller's navigation bar (top of the screen).
  • searchText — string value for the type of place you wish to search for. i.e. "restaurant", "hospital", "supermarket", etc.
  • longitude — numerical value for the longitude value of the place.
  • latitude — numerical value for the latitude value of the place.
  • resultsLimit — number representing the maximum number of results shown in the view controller.
  • 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.

Examples

local facebook = require( "facebook" )

local function facebookListener( 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

facebook.login( "XXXXXXXXXX", facebookListener )  --replace XXXXXXXXXX with your Facebook App ID
Places/Friends
local facebook = require( "facebook" )

local function facebookListener( 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 }, facebookListener )

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