I sat down to crack this thing, and have made a completely new implementation of facebooking for Corona. No need to own enterprise or anything, just copy this and use it instead of your old lua code.
I did not bother to change any of the code, so this is how we’re using it. You need to clean it up and make adjustments for yourself.
We’re giving NO SUPPORT for this piece of code! 
With this Facebook implementation, you’ll get the publish_actions permission from the user and will be able to post photos, scores, achievements etc. No more facebook sdk error #5.
So why does this work? By checking the access_token validity with facebooks open graph server, we’re able to know if the access token is ok to use or not. If it is ok, then we can skip the login phase completely. Second, if the token is _not_ valid, we can clean up our facebook variables, logout the user (logout is not a global function in terms of Corona Facebooking, but app-sandboxed), and pop up the auth dialog.
How to use?
FaceSingleSignon(your\_listener)
local obj = {
message = "Message",
source = { baseDir=system.TemporaryDirectory, filename="image.png", type="image" }
}
FacePublishPhoto(obj)
local facebook = require("facebook")
local appId = "YOUR APP ID"
local fbListener
local fbCommand
local fbData
local fbCallback
local fbId
local LOGOUT = 0
local POST\_MSG = 1
local POST\_PHOTO = 2
local GET\_FRIENDS = 3
local INVITE\_REQUEST = 4
local SINGLE\_SIGNON = 5
local FEED\_GAME = 6
local function printTable( t, label, level )
if label then print( label ) end
level = level or 1
if type(t) ~= "table" then
t = json.decode(t)
end
if t then
for k,v in pairs( t ) do
local prefix = ""
for i=1,level do
prefix = prefix .. "\t"
end
print( prefix .. "[" .. tostring(k) .. "] = " .. tostring(v) )
if type( v ) == "table" then
print( prefix .. "{" )
printTable( v, nil, level + 1 )
print( prefix .. "}" )
end
end
end
end
if simulator then
facebook.login = function()
native.setActivityIndicator(false)
ui.newNotification("Facebook not available in simulator...", "error")
end
else
local old\_login = facebook.login
facebook.login = function(appId, params)
if not \_G.access\_token then
print("Got no access token")
old\_login(appId, fbListener, params)
else
network.request("https://graph.facebook.com/me?access\_token=" .. \_G.access\_token, "GET", function(event)
printTable(event, "facebook.login")
if not event.isError then
local data = event.response or "{}"
data = json.decode(data)
if data and data.error and data.error.type == "OAuthException" then
print("OAuthException")
\_G.access\_token = nil
facebook.logout()
old\_login(appId, fbListener, {"publish\_actions"})
return false
else
-- Everything ok! We'll completely skip the login phase by hacking Coronas native implementation
fbListener({type = "session"})
end
else
-- Something unexpected happened, go ahead with a regular login
print("Face, unexpected error")
old\_login(appId, fbListener, params)
end
end)
end
end
end
fbListener = function(event)
if ("session" == event.type) then
if event.phase == "logout" then
return false
end
-- Save Access Token
if event.token then
\_G.access\_token = event.token
end
if fbCommand == FEED\_GAME then
facebook.showDialog("feed", fbData)
end
if fbCommand == POST\_MSG then
facebook.showDialog("feed", fbData)
end
if fbCommand == POST\_PHOTO then
facebook.request("me/photos", "POST", fbData)
end
if fbCommand == GET\_FRIENDS then
facebook.request("me/friends", "GET", {fields = "id, name, installed"})
end
if fbCommand == INVITE\_REQUEST then
facebook.showDialog("apprequests", fbData)
end
if fbCommand == SINGLE\_SIGNON then
facebook.request("me", "GET", {fields="id,username,name"})
end
-----------------------------------------------------------------------------------------
elseif "request" == event.type then
native.setActivityIndicator(false)
if not event.isError then
local response = json.decode(event.response)
if response then
if fbCommand == POST\_MSG then
ui.newNotification(t("notification.facebook\_message\_posted"))
elseif fbCommand == POST\_PHOTO then
ui.newNotification(t("notification.facebook\_message\_posted"))
elseif fbCommand == GET\_FRIENDS then
fbCallback(response)
elseif fbCommand == SINGLE\_SIGNON then
fbCallback(response)
end
else
ui.newNotification(t("notification.facebook\_request\_failed"), "error")
end
else
-- Error
facebook.logout()
ui.newNotification(t("notification.facebook\_request\_failed"), "error")
fbCallback = nil
fbData = nil
fbCommand = nil
end
elseif "dialog" == event.type then
native.setActivityIndicator(false)
if event.didComplete == true then
if fbCommand == FEED\_GAME or fbCommand == POST\_MSG then
if string.find(event.response or "", "fbconnect://success?post\_id=", 1, true) then
ui.newNotification(t("notification.facebook\_message\_posted"))
end
elseif fbCommand == INVITE\_REQUEST then
local status = "success"
if ios and not string.find(event.response or "", "request=", 1, true) then
status = "error"
end
fbCallback(status)
end
end
fbCallback = nil
fbData = nil
fbCommand = nil
end
end
-- Publish a feed
function FacePublishFeedGame(data)
fbCommand = FEED\_GAME
fbData = data
facebook.login(appId)
end
function FacePublishFeed(data)
fbCommand = POST\_MSG
fbData = data
facebook.login(appId)
end
function FacePublishPhoto(data)
fbCommand = POST\_PHOTO
fbData = data
facebook.login(appId)
end
function FaceInviteFriends(data, cb)
fbCommand = INVITE\_REQUEST
fbData = data
fbCallback = cb
facebook.login(appId)
end
function FaceGetFriends(cb)
fbCommand = GET\_FRIENDS
fbCallback = cb
facebook.login(appId)
end
function FaceSingleSignon(cb)
fbCommand = SINGLE\_SIGNON
fbCallback = cb
facebook.login(appId, {"publish\_actions"})
end
function FaceLogout()
\_G.access\_token = nil
facebook.logout()
end
end
Enjoy a working Facebook implementation again! [import]uid: 21746 topic_id: 34416 reply_id: 142075[/import]