This code works for me. Make sure you remove the facebook.lua file from your project, if you added it in the past.
[lua]local json = require (“json”)
local facebook = require (“facebook”)
– elsewhere in main.lua
function checkConn()
local answer={} – This contains text web page (or other output from server), if it found
local error=“Network OK”
local wawurl=“http://www.google.com” – or another site of your choice
local c,r=http.request{
url = wawurl,
sink = ltn12.sink.table(answer)
}
if r==“host not found” then
error=r
end
if (r~=200 and r~=“host not found”) then
error="HTTP error "…r
end
return error
end
local function facebookListener( event )
print( event.name ) – “fbconnect”
print( event.type ) – type is either “session” or “request”
if ( “session” == event.type ) then
– event.phase is one of: “login”, “loginFailed”, “loginCancelled”, “logout”
if ( “login” == event.phase ) then
– YOUR MESSAGE HERE
local statusUpdate = “YOUR_FACEBOOK_STATUS_POST”
local attachment = {
name = “xxxx”,
message=statusUpdate,
link = “ituneslink”,
caption = “xxxx”,
description = “xxxxx”,
picture = “imageLink”,
actions = json.encode( { { name = “Learn More”, link = “WebLink” } } )
}
facebook.request( “me/feed”, “POST”, attachment ) – posting the message
else
end
elseif ( “request” == event.type ) then
local x = 0.5 * screenW
local y = 0.4 * screenH
flashText (“Request”, x, y)
local function killAlert( event )
if “clicked” == event.action then
native.cancelAlert( alert )
end
end
native.showAlert( “YOUR_FACEBOOK_STATUS_POST”, { “Okay” }, killAlert )
– need printTable function from demo code for this
– event.response is a JSON object from the FB server
–[[ THIS SECTION COMMENTED OUT, REQUIRES TABLEVIEW.LUA and printTable function
local response = event.response
if ( not event.isError ) then
response = json.decode( event.response )
printTable( response, “friends”, 3 )
end
print( response )
–]]
elseif ( “dialog” == event.type ) then
–print( “dialog”, event.response )
end
end
– FACEBOOK BUTTON
local fbButtonPress = function( event )
local check = checkConn()
if check ~= “Network OK” then
local function onCloseApp( event )
if “clicked” == event.action then
native.cancelAlert( alert )
end
end
native.showAlert( “Alert”, "Network error: " … check … “. An internet connection is required to use this function.”, { “Okay” }, onCloseApp )
else
local fbAppID = “xxxxxxxxxxxxxx” --> (string) Your FB App ID from facebook developer’s panel
facebook.login( fbAppID, facebookListener)
end
end[/lua] [import]uid: 1560 topic_id: 4280 reply_id: 14744[/import]