Facebook is now broken!

While I really appreciate the new update, was it really necessary to break the old facebook sample (thus breaking my game)? A simple facebook.newConnection is deprecated would have been nice. Now I have to support the new code whether I want to or not (I want to though…)

That leads me to the second problem and the bug.

I build the facebook sample and I’m getting: “an error occurred with Corona. Please try again later.” So you can understand how I’m a little troubled here. [import]uid: 10835 topic_id: 4280 reply_id: 304280[/import]

You’re right, we could have handled the transition between versions better. For what it’s worth, if you build with the prior SDK release (#109) you can still build with the old Facebook code. But of course you won’t get the new features/fixes in 243.

Regarding the build error, are you building the new Facebook sample in the 243 build, or another version? Is there any further output in the Corona terminal?

Tim [import]uid: 8196 topic_id: 4280 reply_id: 13391[/import]

No, there’s no error on the new Facebook sample. The problem is that I had implemented the old sample in my game and it was working fine. Now I need to figure out what has changed in the new sample to implement it into my game and since I really want to support the new SDK version (finally dynamic scaling spritesheets!) I’m wasting a bit of time on something I had solved (since I don’t need any more advanced Facebook functionality for my game).

Edit: that the code is not commented is just icing on the cake.

Edit2: The fact that I’m getting: “an error occurred with Corona. Please try again later.” is probably due to the fact that I don’t understand the code and haven’t replaced the keys correctly. It builds. There are no errors in the terminal. [import]uid: 10835 topic_id: 4280 reply_id: 13398[/import]

Anyway to get the old facebook code to work? I really don’t want people having to post their own messages and showing an ugly list of friends isn’t really what I want either. I just need to get the old code working again and I’m extremely strapped for time. I’ll be submitting my game to the store today, no matter what, and I’d really hate to have to take out Facebook support for something so silly. [import]uid: 10835 topic_id: 4280 reply_id: 13405[/import]

Here is a code sample that does a posting to the Facebook Wall of the signed in user. This mimics what the previous version of the Facebook sample app did. This code sample replaces the “listener” function in the Facebook sample app shipping with Corona build #243.

[code]
local function listener( 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”


– This code posts a photo image to your Facebook Wall
local attachment = {
name = “Developing a Facebook Connect app using the Corona SDK!”,
link = “http://developer.anscamobile.com”,
caption = “Link caption”,
description = “Corona SDK for developing iOS and Android apps with the same code base.”,
picture = “http://developer.anscamobile.com/demo/Corona90x90.png”,
actions = json.encode( { { name = “Learn More”, link = “http://anscamobile.com” } } )
}

facebook.request( “me/feed”, “POST”, attachment ) – posting the message

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 )
printTable( response, “friends”, 3 )
end
print( response )
elseif ( “dialog” == event.type ) then
print( “dialog”, event.response )
end
end
[/code] [import]uid: 7559 topic_id: 4280 reply_id: 13549[/import]

Sweet! Thanks I was waiting for this!

Edit: Is there anyway to find out what parameters can be used with facebook.request and facebook.showDialog. “me/feed” never crossed my mind and I tried looking at the facebook developer docs, but I don’t know if Corona uses the same parameters (plus I could make very little sense of them). Even a list of accepted parameters would be a big help, then we can experiment ourselves. [import]uid: 10835 topic_id: 4280 reply_id: 13550[/import]

Check out this link on facebook: http://developers.facebook.com/docs/api

facebook.request( “me/feed” ) is converted into https://graph.facebook.com/me/feed

You should be able to figure out the rest from there.

Here is a link to the Facebook objects: http://developers.facebook.com/docs/reference/api/
The Post object is what is used to post a message or item to the Wall.

I will try to update our facebook API pages when I get a chance. We realize that they are very incomplete right now.

-Tom [import]uid: 7559 topic_id: 4280 reply_id: 13554[/import]

Thanks. That’s a big help in the meantime. [import]uid: 10835 topic_id: 4280 reply_id: 13556[/import]

Did it work?

c [import]uid: 24 topic_id: 4280 reply_id: 13569[/import]

I was able to sneak out to try it out. It works! Oh god I’m so hopelessly addicted to this…

Edit: It works as a standalone, but for some reason it doesn’t work in my code. I created a button and it works in the standalone file. However when I copy/paste it into my code the login doesn’t show. Really weird and I wasn’t able to troubleshoot it last night. I know it sees the facebook.login(“apIDnumber”, listener), but after that I don’t know why it doesn’t work.

I guess terminal output on device just shot up to the top of my feature request list. [import]uid: 10835 topic_id: 4280 reply_id: 13604[/import]

Did you change the login section of your code too? My code sample was meant to replace the Listener code in the Facebook sample app that shipped with Corona #243. You need the new login in code to make it work. The way you log in to Facebook is simpler with the new FB library and should be an easy port.

You can get print statement output in the Xcode console by adding the following at the beginning of your code:

io.output():setvbuf('no') -- \*\*debug: disable output buffering for Xcode Console  

-Tom [import]uid: 7559 topic_id: 4280 reply_id: 13644[/import]

Yes of course I changed the login part… I’m not THAT thick. In fact I’m sure there’s nothing wrong with your code since I got it to work just fine replacing it in the facebook sample. I even used the same button code as my game and it worked fine. But when I copy/paste it back, the button does nothing. I replaced json.lua and tableview.lua with the ones from the sample, still no go. The game is seeing the listener because I get the facebook.login() not supported message in terminal on the simulator. If I remove the listener that message is not shown. Even with a blank listener it doesn’t work (It shows the login screen if I do it in the sample). So I’m not sure exactly what is breaking it in my code.

I’ll be sure to give a try to the Xcode console, though other than using it to transfer the game to the device I haven’t used Xcode at all. I’ll see how it goes. Thanks again for the help.
[import]uid: 10835 topic_id: 4280 reply_id: 13648[/import]

I fixed it by the way. I forgot to delete the old facebook.lua file from my folder, so that was causing all sorts of stupidity (since my code was requiring it). Since I added it so long ago (and have so many files on my build folder) I’d forgotten it was required. It wouldn’t hurt to remind people upgrading to delete that file. [import]uid: 10835 topic_id: 4280 reply_id: 13759[/import]

Great news. Glad you got it working and thanks for the feedback.

-Tom [import]uid: 7559 topic_id: 4280 reply_id: 13786[/import]

I would like to know if there’s a way to prevent the Facebook empty dialog that shows up all the time facebook.login is invoked and the user is already logged in. [import]uid: 10048 topic_id: 4280 reply_id: 14097[/import]

I’d like to know that too.

Also, how would one access the user’s FB name?

Something like:
[lua] local name = facebook.request( “me/first_name”)
local response = event.response
if ( not event.isError ) then
response = json.decode( event.response )
end
[/lua] [import]uid: 1560 topic_id: 4280 reply_id: 14412[/import]

I believe the blank Facebook page is coming from the Facebook’s API and I’m not sure we have any control over that.

Requesting the information for “me” will return a JSON table of information in the response event.

facebook.request( "me" )  

See the Facebook documentation for response information: http://developers.facebook.com/docs/reference/api/user [import]uid: 7559 topic_id: 4280 reply_id: 14417[/import]

Tom,

if i use the example that comes with .243, whatever i type in the text field is posted on the wall.
when i replace the listener function with this one, nothing is published, and on the console i see this:
“The user hasn’t authorized the application to perform this action”
“OAuthException”
i use the same login for both…

i just found out that the listener function works fine
for some reason the api key and secret are OK for a facebook application but its id is not, even though the application name appears on the facebook login screen.
i used another application id and the message was published.

thank you!

[import]uid: 6459 topic_id: 4280 reply_id: 14455[/import]

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]

Has the fb issue been resolved? I’m trying to use the example above but am getting no luck (with my app id)…

[import]uid: 9046 topic_id: 4280 reply_id: 15566[/import]