Problems implementing Facebook

local function facebookListener( event ) print( "event.name", event.name ) --"fbconnect" print( "event.type:", event.type ) --type is either "session", "request", or "dialog" print( "isError: " .. tostring( event.isError ) ) print( "didComplete: " .. tostring( event.didComplete ) ) --"session" events cover various login/logout events --"request" events handle calls to various Graph API calls --"dialog" events are standard popup boxes that can be displayed if ( "session" == event.type ) then --options are: "login", "loginFailed", "loginCancelled", or "logout" if ( "login" == event.phase ) then local access\_token = event.token --code for tasks following a successful login facebook.request( "me/feed", "POST", { message="Score: ".. tostring( newScore ) } ) end elseif ( "request" == event.type ) then print("facebook request") if ( not event.isError ) then local response = json.decode( event.response ) --process response data here end elseif ( "dialog" == event.type ) then print( "dialog", event.response ) --handle dialog results here end end local function onShareBtnRelease() --local screenCap = display.captureScreen( true ) local json = require( "json" ) local facebook = require( "facebook" ) local fbAppID = "1xxxxxxxxxxx9" -- App ID facebook.login( fbAppID, facebookListener, { "publish\_actions, email" } ) end

This is my code which runs when social button is pressed.

Now in phones which have facebook app installed, it just asks for email address and basic info. When i press ok, nothing happens

In phones which do not have facebook app installed, it always publishes Score:nil
Please help. Thanks
 

Hi @sarthakmadan96,

One immediate problem I notice is that you’re require()-ing both the Facebook and JSON libraries out-of-scope from the function (facebookListener) which uses them. You need to scope this properly under the Lua rules. There may be some other issues as well, but the first thing yoiu must fix is the scoping.

Best regards,

Brent

Hi @sarthakmadan96,

One immediate problem I notice is that you’re require()-ing both the Facebook and JSON libraries out-of-scope from the function (facebookListener) which uses them. You need to scope this properly under the Lua rules. There may be some other issues as well, but the first thing yoiu must fix is the scoping.

Best regards,

Brent