Type Function Return value none Revision Release 2022.3683 Keywords Facebook, setFBConnectListener See also facebook.login() facebook.* fbconnect
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.
facebook.setFBConnectListener( listener )
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/" )