Facebook not working

Hey Guys, Would just like to say thankyou in advance for helping. Trying to get a Facebook integration working in my Game by for some reason when I test it on a device it just dose not work.

Here is my code

local onFBTouch = function( event )  
 if event.phase == "release" and fbBtn.isActive then  
 audio.play( tapSound )  
 local facebookListener = function( event )  
 if ( "session" == event.type ) then  
 -- upon successful login, update their status  
 if ( "login" == event.phase ) then  
  
 local theMessage = "Just finished a level in Game 1"  
  
 facebook.request( "me/feed", "POST", {  
 message=theMessage ,  
 name="Test",  
 caption="Test",  
 link="none",  
 picture="none" } )  
 end  
 end  
end   
  
 facebook.login( "195606120481762", facebookListener, { "publish\_stream" } )  
 end  
end  
  
 fbBtn = ui.newButton{  
 defaultSrc = "images/FaceBook.png",  
 defaultX = 295,  
 defaultY = 35,  
 overSrc = "images/FaceBook.png",  
 overX = 295,  
 overY = 35,  
 onEvent = onFBTouch,  
 id = "FacebookButton",  
 text = "",  
 font = "Helvetica",  
 textColor = { 255, 255, 255, 255 },  
 size = 16,  
 emboss = false  
 }  
  
 fbBtn.x = 240; fbBtn.y = 240  
 fbBtn.alpha = 1  
  

and I have local facebook = require "facebook" at the start of my code.

now when I test this on the device the FB logo screen comes up but when I put in my data it just flashes and nothing is posted to Facebook.

Any Ideas on what could be causing this? [import]uid: 40417 topic_id: 9795 reply_id: 309795[/import]

Hey there, you’re using an older method - check out this tutorial.

http://techority.com/2011/04/21/updated-facebook-tutorial-for-iphone/

Should work perfectly :slight_smile:

Peach [import]uid: 52491 topic_id: 9795 reply_id: 35694[/import]

I had a look at the example and copy/pasted the code into my level1.lua file, I removed some of the un-needed code and only left the parts to post the PHOTO-POST, when building my app the same thing occured.

  1. Click on FB button (loads FB login screen in app)
  2. After loggin in FB screen closes immediantly and no post on FB

Here is the code I am using now.

Top of my level1.lua

local facebook = require("facebook")  
local fbCommand -- forward reference  
local POST\_PHOTO = 4  
local appId = "195606120481762"  
local json = require("json")  

seperate function in level1.lua

local function facebookListener( event )  
 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  
  
 if fbCommand == POST\_PHOTO then  
 local attachment = {  
 name = "Brady's Adventure",  
 link = "http://roedangames.net.au",  
 caption = "Just finished a level in Bradys's Adventure, Come try it out in the App Store",  
 description = "Brady's Adventure ",  
 picture = "http://roedangames.net.au/wp-content/uploads/2011/04/Icon.png",  
 --actions = json.encode( { { name = "Learn More", link = "http://anscamobile.com" } } )  
 }  
  
 facebook.request( "me/feed", "POST", attachment ) -- posting the photo  
 end  
 end  
 end  

In my HUD function

[code]
– Now Display the Facebook Button and link to Facebook Function
local onFBTouch = function( event )
print(“Pressing Facebook Button” … "App ID: " … appId)
if event.phase == “release” then
fbCommand = POST_PHOTO
facebook.login( appId, facebookListener, {“publish_stream”} )

end
end

fbBtn = ui.newButton{
defaultSrc = “images/FaceBook.png”,
defaultX = 295,
defaultY = 35,
overSrc = “images/FaceBook.png”,
overX = 295,
overY = 35,
onEvent = onFBTouch,
id = “FacebookButton”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}

fbBtn.x = 240; fbBtn.y = 240
fbBtn.alpha = 1
[/code] [import]uid: 40417 topic_id: 9795 reply_id: 35788[/import]

Have you been able to successfully post a wall message from the app?

Check your applications on Facebook and see if your app is listed as something to recently access your account; if so, let me know what your Facebook settings are. (FB end, not within your code.)

Peach :slight_smile: [import]uid: 52491 topic_id: 9795 reply_id: 35862[/import]

Hey Peach,

Went over my code again was 3:00am last night when I last had a look at the code, Have it working now, lol stupid me didn’t read the code correctly and stuffed it up being tired.

Thanks for all the help and the link it worked great :smiley:

Thanks and Regards
Danny Roerring - Roedan Games [import]uid: 40417 topic_id: 9795 reply_id: 35870[/import]

Not stupid at all; we all do it. You’d be amazed at some of MY 3 AM errors…

Peach :wink: [import]uid: 52491 topic_id: 9795 reply_id: 36079[/import]