Hello amazing guys,
I’m having some problems integrating facebook into my game. Basically the login popup works, I can login, grant permissions to my app… and then… the popup disappears and it brings me back to my game… without posting anything at all on my wall…
Thanks in advance for the help!
This is my code:
[code]function facebookListener( event )
— End of debug Event routine -------------------------------------------------------
print( “event.name”, event.name ) – “fbconnect”
print( “event.type:”, event.type ) – type is either “session” or “request” or “dialog”
print( "isError: " … tostring( event.isError ) )
print( "didComplete: " … tostring( event.didComplete) )
– After a successful login event, send the FB command
– Note: If the app is already logged in, we will still get a “login” phase
if ( “session” == event.type ) then
– event.phase is one of: “login”, “loginFailed”, “loginCancelled”, “logout”
statusMessage.textObject.text = event.phase – tjn Added
print( "Session Status: " … event.phase )
if event.phase ~= “login” then
– Exit if login error
return
end
– The following displays a Facebook dialog box for posting to your Facebook Wall
if fbCommand == SHOW_DIALOG then
facebook.showDialog( {action=“stream.publish”} )
end
– This code posts a message to your Facebook Wall
if fbCommand == POST_MSG then
local time = os.date("*t")
local postMsg = {
message=“Hey I’m playing Flying Squirrel on my iPhone and I scored " … score … " points!”,
name=“Do you think you can beat my score?”,
caption=“Play Flying Squirrel now to find out!”,
link=“http://www.drowne.com”,
picture=“http://www.drowne.com/images/squirrelloading.png” }
facebook.request( “me/feed”, “POST”, postMsg ) – posting the message
end
elseif ( “request” == event.type ) then
– event.response is a JSON object from the FB server
local response = event.response
if ( not event.isError ) then
response = json.decode( event.response )
if fbCommand == POST_MSG then
print( response, “message”, 3 )
statusMessage.textObject.text = “Message Posted”
else
– Unknown command response
print( “Unknown command response” )
statusMessage.textObject.text = “Unknown ?”
end
else
– Post Failed
statusMessage.textObject.text = “Post failed”
printTable( event.response, “Post Failed Response”, 3 )
end
elseif ( “dialog” == event.type ) then
– showDialog response
print( “dialog response:”, event.response )
statusMessage.textObject.text = event.response
end
end
local statusMessage
function publishOnFacebook()
statusMessage = createStatusMessage( “Not connected”, 0.5*display.contentWidth, 30 )
fbCommand = POST_MSG
facebook.login( appId, facebookListener, {“publish_stream”} )
end[/code] [import]uid: 23177 topic_id: 13976 reply_id: 313976[/import]
[import]uid: 52491 topic_id: 13976 reply_id: 51548[/import]