facebook.setFBConnectListener

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

Overview

Sets the listener function which will receive fbconnect events. This can be used to define a listener when there's no need for a facebook.login() 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/" )