Facebook Login - Nothing Is Happening

Hello!

First, just want to say thanks to the devs at Corona Labs for creating a fantastic framework. Most of my app development has gone pretty smoothly, until i tried to incorporate facebook :(. 

Here is my issue

When my game ends, a user is presented with an overlay. They can tap a button that says “Share Score” which should ask them to login to facebook, and afterwards i would post their score to their feed. The problem lies in the facebook.login(…) part.

I have verified that the plugin is included in the build.settings using corona’s documentation. It looks like this:

plugins = { ["facebook"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, ["iphone-sim"]=true }, }, }, 

The iOS specific part of the build.settings looks like this:

iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay FacebookAppID = "HIDDEN\_APP\_ID", --replace XXXXXXXXXX with your Facebook App ID --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend --[[-- iOS app URL schemes: --]] CFBundleURLTypes = { { CFBundleURLSchemes = { "fbHIDDEN\_APP\_ID", "coronasdkapp", } } } } }, 

In the scene that handles the overlay, I included the facebook library and the json library. I then call facebook.login(“APP_ID”, eventListener, “PERMISSIONS”) when they tap on a button. However nothing happens when i do this. I added print statements before the facebook.login call and after it. I can see those messages print in the xcode organizer’s console (im testing this on my iPhone 5), so i know its actually executing, but nothing happens.

I’ve been stuck on this for about 2 or 3 hours now :/. Looked over the documentation again and again. Hope to hear from someone soon. Thanks!!

Can you post your code where you’re calling facebook.login

Here is the code:

local function cancelAction(event, onAfterCancel) local target = event.target target:setFillColor(.7) print("BEFORE FACEBOOK LOGIN"); facebook.login( fbAppId, facebookListener, { "publish\_actions, email" } ); print("After FACEBOOK LOGIN"); delayAction(120, function() --onAfterCancel() end) end

The facebook library and json library are included at the very top of this scene. I also included both libraries in main.lua. 

The facebook listener does nothing but print statements to the console. But it’s not printing anything, so i assume it’s not getting called.

Normally you need to call facebook.login() without any permissions.  Then when you are ready to write you  call facebook.login() again asking for the permissions.

They probably should be:

facebook.login( fbAppId, facebookListener, { “publish_actions”, “email” } );

Hey Rob

Thanks for the information. I tried just doing facebook.login(fbAppId, facebookListnere) --omitted permissions, but i still get the same result. Maybe because i’m calling the function in an overlay? What’s weird is that i dont get any error messages…

Can you try the Facebook sample app and see if it works for you?

Also here is the most simple facebook sample code, that is known to work.  Perhaps between the sample app and this, we can pin point it its a problem with your http://developers.facebook.com setup, a device issue (is the facebook native app installed?  do you have a login for Facebook setup in the Settings app?)

io.output():setvbuf('no') local widget = require( "widget" ) local json = require( "json" ) local facebook = require( "facebook" ) local facebookAppID = "XXXXXXXXXXXXXXX" local FB\_Command = nil function print\_r ( t )     local print\_r\_cache={}     local function sub\_print\_r(t,indent)         if (print\_r\_cache[tostring(t)]) then             print(indent.."\*"..tostring(t))         else             print\_r\_cache[tostring(t)]=true             if (type(t)=="table") then                 for pos,val in pairs(t) do                     if (type(val)=="table") then                         print(indent.."["..pos.."] =\> "..tostring(t).." {")                         sub\_print\_r(val,indent..string.rep(" ",string.len(pos)+8))                         print(indent..string.rep(" ",string.len(pos)+6).."}")                     elseif (type(val)=="string") then                         print(indent.."["..pos..'] =\> "'..val..'"')                     else                         print(indent.."["..pos.."] =\> "..tostring(val))                     end                 end             else                 print(indent..tostring(t))             end         end     end     if (type(t)=="table") then         print(tostring(t).." {")         sub\_print\_r(t,"  ")         print("}")     else         sub\_print\_r(t,"  ")     end     print() end local function facebookListener( event )     print\_r( 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 ) )     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             print( 'Token: ' .. access\_token )             if FB\_Command then                 facebook.request( FB\_Command )             end         end     elseif ( "request" == event.type ) then         print("facebook request")         if ( not event.isError ) then             local data = json.decode( event.response )             print( "data: ", data )             print( "event.response: ", event.response )         else             print( "event.isError: " .. event.isError )         end     end end local function doFacebook( event )     if event.phase == "ended" then         FB\_Command = "me"         facebook.login( facebookAppID, facebookListener, {"publish\_actions", "email" })     end end local fbButton = widget.newButton({     label = "Facebook",     onEvent = doFacebook     }) fbButton.x = display.contentCenterX fbButton.y = display.contentCenterY facebook.login( facebookAppID, facebookListener )

Hey Rob, 

Thanks for all your help. I got it to work by creating an anonymous function as the Facebook listener. Doing that caused the login and other functions to work fine. It’s possible that I mistyped the facebook listener function’s name…silly me. Sorry for taking up your time. 

Again, thanks for all your help!

Can you post your code where you’re calling facebook.login

Here is the code:

local function cancelAction(event, onAfterCancel) local target = event.target target:setFillColor(.7) print("BEFORE FACEBOOK LOGIN"); facebook.login( fbAppId, facebookListener, { "publish\_actions, email" } ); print("After FACEBOOK LOGIN"); delayAction(120, function() --onAfterCancel() end) end

The facebook library and json library are included at the very top of this scene. I also included both libraries in main.lua. 

The facebook listener does nothing but print statements to the console. But it’s not printing anything, so i assume it’s not getting called.

Normally you need to call facebook.login() without any permissions.  Then when you are ready to write you  call facebook.login() again asking for the permissions.

They probably should be:

facebook.login( fbAppId, facebookListener, { “publish_actions”, “email” } );

Hey Rob

Thanks for the information. I tried just doing facebook.login(fbAppId, facebookListnere) --omitted permissions, but i still get the same result. Maybe because i’m calling the function in an overlay? What’s weird is that i dont get any error messages…

Can you try the Facebook sample app and see if it works for you?

Also here is the most simple facebook sample code, that is known to work.  Perhaps between the sample app and this, we can pin point it its a problem with your http://developers.facebook.com setup, a device issue (is the facebook native app installed?  do you have a login for Facebook setup in the Settings app?)

io.output():setvbuf('no') local widget = require( "widget" ) local json = require( "json" ) local facebook = require( "facebook" ) local facebookAppID = "XXXXXXXXXXXXXXX" local FB\_Command = nil function print\_r ( t )     local print\_r\_cache={}     local function sub\_print\_r(t,indent)         if (print\_r\_cache[tostring(t)]) then             print(indent.."\*"..tostring(t))         else             print\_r\_cache[tostring(t)]=true             if (type(t)=="table") then                 for pos,val in pairs(t) do                     if (type(val)=="table") then                         print(indent.."["..pos.."] =\> "..tostring(t).." {")                         sub\_print\_r(val,indent..string.rep(" ",string.len(pos)+8))                         print(indent..string.rep(" ",string.len(pos)+6).."}")                     elseif (type(val)=="string") then                         print(indent.."["..pos..'] =\> "'..val..'"')                     else                         print(indent.."["..pos.."] =\> "..tostring(val))                     end                 end             else                 print(indent..tostring(t))             end         end     end     if (type(t)=="table") then         print(tostring(t).." {")         sub\_print\_r(t,"  ")         print("}")     else         sub\_print\_r(t,"  ")     end     print() end local function facebookListener( event )     print\_r( 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 ) )     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             print( 'Token: ' .. access\_token )             if FB\_Command then                 facebook.request( FB\_Command )             end         end     elseif ( "request" == event.type ) then         print("facebook request")         if ( not event.isError ) then             local data = json.decode( event.response )             print( "data: ", data )             print( "event.response: ", event.response )         else             print( "event.isError: " .. event.isError )         end     end end local function doFacebook( event )     if event.phase == "ended" then         FB\_Command = "me"         facebook.login( facebookAppID, facebookListener, {"publish\_actions", "email" })     end end local fbButton = widget.newButton({     label = "Facebook",     onEvent = doFacebook     }) fbButton.x = display.contentCenterX fbButton.y = display.contentCenterY facebook.login( facebookAppID, facebookListener )

Hey Rob, 

Thanks for all your help. I got it to work by creating an anonymous function as the Facebook listener. Doing that caused the login and other functions to work fine. It’s possible that I mistyped the facebook listener function’s name…silly me. Sorry for taking up your time. 

Again, thanks for all your help!