facebook.showDialog()

Type Function
Return value Event
Revision Release 2024.3703
Keywords Facebook, showDialog
See also facebook.login()
facebook.*
fbconnect

Overview

Displays an interactive Facebook UI dialog for publishing posts to a user’s stream, inviting friends to your app, etc. Use facebook.request() if you need the application itself to do the posting.

The response from the dialog comes back in the form of a fbconnect event that is sent to the listener specified within facebook.setFBConnectListener() or facebook.login().

Syntax

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

String. The dialog you want to show. Valid options include:

params (required)

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 parameters which are available for the dialog that you want to show — see Share Dialog and Game Requests Dialog below for details.

Share Dialog

Displays the Facebook dialog for sharing content. For this dialog, action should be either "link" or "photo".

Note
  • On Android, for a shared link to be posted from your app, you must ensure that Application Name provided when building the app from the Corona Simulator matches the Display Name field in the Facebook Developer Portal. For Solar2D Native developers, this requirement is outlined here.

  • To share photos with the Share Dialog, version 7.0 or higher of a Facebook app must be installed on the device.

For this dialog, the params table can contain the following key-value pairs. Note that some keys are required while others are not.

Game Request Dialog

Displays a native view which allows the user to send game requests to their choice of friends. For this dialog, action should be "requests".

Notes

For this dialog, the params table can contain the following key-value pairs.

Examples

Share Dialog
local facebook = require( "plugin.facebook.v4" )

local function facebookListener( event )

    if ( "session" == event.type ) then
        if ( "login" == event.phase ) then

            local shareParams = {
                link = "https://www.coronalabs.com/",
                title = "Corona Labs"
            }
            facebook.showDialog( "link", shareParams )
        end

    elseif ( "dialog" == event.type ) then
        print( event.response )
    end
end

facebook.login( facebookListener )
Game Request
local facebook = require( "plugin.facebook.v4" )

local function facebookListener( event )

    if ( "session" == event.type ) then
        if ( "login" == event.phase ) then
        
            facebook.showDialog( "requests", 
                { 
                    message = "You should download this game!",
                    filter = "APP_NON_USERS"
                })
        end

    elseif ( "dialog" == event.type ) then
        print( event.response )
    end
end

facebook.login( facebookListener )