facebook.setFBConnectListener

Type Function
Return value none
Revision 2017.3060
Keywords facebook, setFBConnectListener
See also facebook.login()
facebook.*
fbconnect

Overview

Sets the "fbconnect" listener that the Facebook plugin will use after dispatching a fbconnect event. This can be used when the listener needs to change but there's no need for a facebook.login(), facebook.request(), or facebook.showDialog() call.

Syntax

facebook.setFBConnectListener( listener )
listener (required)

Listener. A listener that responds to fbconnect events. If this is a table, it should have a property "fbconnect" that is a function.

Example

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

-- Check for a value inside the provided table
local function valueInTable( t, valueToFind )
    for k,v in pairs( t ) do
        if v == valueToFind then
            return true
        end
    end
    return false
end

local function facebookListener( event )
    if ( "session" == event.type ) then
        -- Handle login event and try to share the link again if needed
    elseif ( "dialog" == event.type ) then
        -- Handle dialog event
    end
end

local function shareLink( url )
    local accessToken = facebook.getCurrentAccessToken()
    if accessToken == nil then
        facebook.login()
    elseif not valueInTable( accessToken.grantedPermissions, "publish_actions" ) then
        facebook.login( { "publish_actions" } )
    else
        facebook.showDialog( "link", { link=url } )
    end
end

-- Set the "fbconnect" listener from the start
facebook.setFBConnectListener( facebookListener )

-- Sometime later, share a link
shareLink( "https://www.coronalabs.com/" )