Interestingly there are like three threads reporting a similar issue, which would lead me to suspect there is a problem I’ve spent my time today constructing a very basic Facebook app. I’ve verified that it runs correctly on both iOS 7 (iPhone 5) and on Android 4.4 (Google Nexus 7).
build.settings
settings = { orientation = { default = "portrait", supported = { "portrait" } }, android = { usesPermissions = { "android.permission.INTERNET", }, }, plugins = { -- key is the name passed to Lua's 'require()' This section is only required for builds \> 2014.2165 ["facebook"] = { -- required publisherId = "com.coronalabs", supportedPlatforms = { iphone = true, ["iphone-sim"] = true }, }, }, iphone = { plist = { CFBundleIconFile = "Icon.png", CFBundleIconFiles = { "Icon.png", "Icon@2x.png", "Icon-60.png", "Icon-60@2x.png", "Icon-72.png", "Icon-72@2x.png", "Icon-76.png", "Icon-76@2x.png", "Icon-Small.png", "Icon-Small@2x.png", "Icon-Small-40.png", "Icon-Small-40@2x.png", "Icon-Small-50.png", "Icon-Small-50@2x.png", }, UIApplicationExitsOnSuspend = false, -- must be false for single sign-on to work FacebookAppID = "XXXXXXXXXXXXXX", -- replace XXXXXXXXX with your facebook appId CFBundleURLTypes = { { CFBundleURLSchemes = { "fbXXXXXXXXXXXXXX", -- replace XXXXXXXXX with your facebook appId } } } } } }
main.lua
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 )
This should be minimalist Facebook app. It does a 2 pass login, the first time requesting basic permissions, then when you hit the button, it asks for additional permissions. Once your app runs and these have been granted you won’t be prompted again. The things printed to the console log are the things I would expect to see.
You can use this or use the Sample app in the SampleCode/Network/Facebook folder to verify your settings.
I will be up front and was very frustrated because it just wasn’t working for me. Then I used the build.settings from the sample app replacing my build.settings. It suddenly started working. This is another thing you can try. Replace your build.settings with the one from the sample app.
Rob