Type Function Return value none Revision Release 2024.3703 Keywords Facebook, init See also facebook.login() facebook.* fbconnect fbinit
Sets the listener function which will receive a fbinit event once initialization of the Facebook SDK is complete.
This method also sets the same listener function as the default listener for fbconnect events, so there’s no need to call facebook.setFBConnectListener() unless you want to use a different listener for fbconnect events versus the fbinit event.
Initialization of the Facebook SDK is automatically triggered when the plugin is required. This call provides a way to determine when initialization is complete. We strongly recommended that you wait for initialization to complete before making calls like facebook.login() or facebook.publishInstall().
facebook.init( listener )
Listener. A listener that responds to fbinit events and, optionally, fbconnect events. If this is a table, it should have a property "fbinit"
that is a function.
local facebook = require( "plugin.facebook.v4a" ) -- 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 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 local function facebookListener( event ) if ( "fbinit" == event.name ) then print( "Facebook initialized" ) -- Initialization complete; share a link shareLink( "https://www.coronalabs.com/" ) elseif ( "fbconnect" == event.name ) then 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 end -- Set the "fbinit" listener to be triggered when initialization is complete facebook.init( facebookListener )