Facebook 3.1.1 SDK breaks A LOT

Fixed. Rewrote the plugin to use iOS functionality instead of Facebook functionality:

SLComposeViewController\*fvc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];  
  
...  

With that we were able to switch to daily 1030 and continue presenting the users with native share dialogs. [import]uid: 21746 topic_id: 34416 reply_id: 143042[/import]

Okay, I get same native alert with both daily build 990 and 1013, plus errors that previously did not exist.

It turns out it has something to do with installing it on iOS6.1 device. The app built with iOS SDK 6.0 via daily build 990 spits out the very same errors when installed on a device with iOS6.1.

The app works only if I build it with daily build 990 and install it on a device with iOS 6.0 (or pre-iOS 6.0) At this point, I don’t have an app with FB feature that runs without any error on iOS6.1 device. Yikes. This is a major setback. Back to code review – and I really have to work on getting Haakon’s workaround working with daily build 1025 – otherwise, my app submission is not happening.

EDIT: The strange native alert was something to do with testing on a device that has already FB approved (via a version of an app built with iOS6.0 SDK). Instead of wiping the device, I simply deleted the app and then installed a new version of the app built with iOS6.1 SDK – this triggered this strangeness and inexplicable errors that I could not work around. Once I wiped the device (by resetting all content) and installed the new version of the app built with iOS6.1 SDK, the odd alerts and error messages went away – meaning, once I clean slated the devices (both iOS6.0 device and iOS6.1 device), the app built with 1025 returned back to the behavior I observed in CASE 5 & CASE 7, and yes, restarting the app does fix the Facebook issue and normalize the app. (The strange errors would’ve been worrisome if I had an already released app built with pre-iOS6.1SDK that desperately needed the update/fix with the new Facebook SDK.)

The next step – if I got the energy and can put aside some time for it, I might just go ahead and create a test project that only include main.lua with code that demonstrates CASE 7 (and perhaps I’ll send it in to Corona in case that helps identify where our trouble lies.) And then, I may proceed to convert the test project to include Haakon’s work around. If the work around works in the reworked version of the test project, then I have a reason to further rework my app – and perhaps send the reworked test project to Corona too so that they may finally get around to fixing the issue…

EDIT 2: I filed Case 20794 with the test project that demonstrates CASE 7 (tested with daily build 1025 on both iOS 6.0.1 and iOS 6.1 devices). The test project is stripped down to the core FB mechanics that fails. In the process, I found that if I install the test app on cleanly wiped device, it normalizes after I restart the app upon encountering the HTTP 400 error and other FB failures. Once it normalizes, the FB feature works flawlessly. However, if I delete the app from the device, and reinstall the very same app, the FB feature is completely destroyed, and the app becomes utterly dysfunctional. [import]uid: 67217 topic_id: 34416 reply_id: 142154[/import]

I hope you don’t mind me jumping into this thread…

I’ve been reading this thread over and over with a lot of interest (thanks Naomi and haakon), but I am unsure what I need to do to make my app play nice with Facebook.

I want to add a Like button, wall posting, and maybe a way to grab friends for a challenge mode in my app (that depends on what Game Minion will deliver I guess), and I am unsure what build to use, what params to pass to FB, and what return and/or error values to expect.

Even in simpler times, facebook integration was something I wasn’t sure about successfully implementing. With my new app, I need to add more fb features, and now I am just completely confused.

Will there be an improvement in the builds to handle this (soon)? If not, what’s the solution? I also tried the GGFacebook library with limited success… perhaps whatever happened also affected this library?

FB integration is almost a must now, so any help sorting this out woudl be great. [import]uid: 114363 topic_id: 34416 reply_id: 142285[/import]

Just an update on this issue. We understand this is a major issue and we are looking into this problem now and hope to have a resolution very soon.

Thanks,
Tom [import]uid: 7559 topic_id: 34416 reply_id: 142418[/import]

Naomi (and Tom),

By accident I tried to post a payload to facebook.request that had illegal content. It actually led to the problems described in this thread, the facebook error 5.

I know for sure my implementation works fine, we have tested it extensively for several days. So Naomi, I’m thinking that you are maybe posting some data that is not valid since you’re still getting the error.

You can test it by trying to issue a post to me/photos with this payload:

WORKS

local obj = {  
 message = "Corona SDK",  
 source = { baseDir=system.TemporaryDirectory, filename="image.png", type="image" }  
}  
FacePublishPhoto(obj)  

FAILS with error and causes a lot of trouble

local obj = {  
 message = "Corona SDK",  
 source = 'http://www.coronalabs.com/wp-content/uploads/2012/06/Built\_with\_Corona\_SM.png',  
}  
FacePublishPhoto(obj)  

My point is, if you have a payload that does not validate, Corona handles the error from Facebook horribly. It completely destroys the facebook functionality in Corona. Which is what is happening for you, Naomi. I’d like to see that test project you created, would you mind sending it to me? haakon ÆT monkeybin.no [import]uid: 21746 topic_id: 34416 reply_id: 142422[/import]

@Tom, thank you. Looking forward to the resolution.

@haakon, I haven’t touched my code after I reverted it back to my pre-workaround code. Perhaps when I converted to incorporate your workaround, it worked – except that I didn’t clean slate my device, and some FB related cookie was still on device, causing it to disturb my test process – I don’t know. The errors I ended up with (after I implemented your workaround) was the same errors that I get when I delete the app and reinstall the very same app. Does your app have no issue after you install it, test it thoroughly, delete it and then reinstall it – assuming you are building your app with iOS6.1 SDK? If it works, then I may not have implemented your workaround properly.

Anyhow, yes, I’ll send you the test project. Let me know if you spot anything odd. If you end up implementing your workaround on the test project, it would be nice if you can send it back.

Naomi

Edit: Haakon, I just sent you the test project. BTW, is this illegal for facebook.showDialog? But then, if it’s illegal, why does it work after I restart the app?

local attachment = {  
 app\_id = appID,  
 to = friendID,  
 link = "http://www.coronalabs.com",  
 picture = "http://www.coronalabs.com/wp-content/uploads/2012/06/Built\_with\_Corona\_SM.png",  
 name = "I Hit a New High Score!!",  
 description = "I made a new high score in this game!"  
 }  
facebook.showDialog( "feed", attachment )  

[import]uid: 67217 topic_id: 34416 reply_id: 142429[/import]

lol … after reading all the frustration caused by this issue and facing it myself now i notice that just above this box where i am typing is a solution … “Need immediate assistance? Get Premium Support.” …

+1 for fixing this

Thanks for the code Haakon … will give it s spin if this is not addressed in the next day or two. [import]uid: 118012 topic_id: 34416 reply_id: 142450[/import]

Just an update on the iOS Facebook SDK 3.0 issue. We reworked our internal FB 3.1.1 interface and believe we have resolved the major issues. We tested against the Facebook Sample App as well as Naomi’s test case (#20794). The changes will in the next daily build (1028 and later). We will continue to test and please report any problems you find.

We tried to not make any breaking API changes so there should be no changes to existing Corona code.

Thanks,
Tom [import]uid: 7559 topic_id: 34416 reply_id: 142584[/import]

Tom, this is fantastic! Thank you. I’ll grab daily build 1028 as soon as it becomes available, and yes, I’ll post if I encounter any problems.

Thanks again!

Naomi
[import]uid: 67217 topic_id: 34416 reply_id: 142586[/import]

To use Facebook with build 1028 there is one change needed to your Facebook project. You need to add your Facebook App ID to another place in the build.setting file.

plist={ FacebookAppID = "xxxxxxxxxxxxxx", CFBundleURLTypes = { { CFBundleURLSchemes = { "fbxxxxxxxxxxxxxx", }, }, },},[/code] [import]uid: 7559 topic_id: 34416 reply_id: 142641[/import]

Thank you Tom. We’ll have a look at this today and see what kind of results we get and report back here.

[import]uid: 120928 topic_id: 34416 reply_id: 142652[/import]

@cebodine, a quick note to let you know that I found there are still some FB issues with daily build 1028 (after revising the build.settings per Tom’s instruction.) Tom is aware of my test result. And now, I’ll sit tight and wait for another good news.

Naomi [import]uid: 67217 topic_id: 34416 reply_id: 142656[/import]

Hi Tom,

We are still experiencing problems with build 1028. In the call to facebook.login, we have been wrapping the listener parameter with a lua enclosure to provide context information to the listener:

 facebook.login( game.facebookAppId,  
 function(event)  
 listener(request, event)  
 end,  
 request.permissions  
 )  

The request table includes all of the required data to send to facebook (path, method, attachment), and what action(s) to take upon receipt. This avoids having to define global variables and facilitated concurrent processing of multiple facebook requests.

With the latest build, we can confirm that the enclosure passed to the FIRST login call is now used for all subsequent listener invocations. To some extent, we might be able to work around this, but it will require blocking all user activity until each request is completed. This used to work quite well.

What we really need is the ability to pass a different listener for each facebook.request in the same manner as network.request. The current implementation requires the listener to depend upon global (or at least module level) variables to determine context. [import]uid: 120928 topic_id: 34416 reply_id: 142689[/import]

@cebodine, can you provide some code around the snippet you posted so we can see the context in which it’s used? If you prefer, you can email me directly something that I can test against to better understand the issue. tom at coronalabs dot com.

Have you seen any other issues in your test of 1028?

Thanks,
Tom [import]uid: 7559 topic_id: 34416 reply_id: 142700[/import]

A quick update to let you all know that Daily Build 1028 fixed the issue for me. The final issue that I had with the 1028 was something to do with a device that previously had FB error. I didin’t clean slate the device, and the newly built app got tripped by the lingering issue. Once I wiped the device and then installed the same app, the error went away.

Tom, thank you so much for fixing this!!!

Naomi [import]uid: 67217 topic_id: 34416 reply_id: 142703[/import]

Hi Tom,

I don’t really have time at the moment to put together a full working demonstration that is not our complete project, but here are a few larger snipets… Right now, I am away from my mac, so I cannot build this for device. and test

facebookUI.lua

local facebook = require("facebook")  
local json = require("json")  
  
local factory = {}  
  
-- Facebook Session States  
local fbPhases = {  
 login = "Logged In",  
 loginFailed = "Login Failed",  
 loginCancelled = "Login Cancelled",  
 logout = "Logged Out",  
}  
-- Facebook Connection listener  
--  
local function listener( request, event )  
  
 -- print("facebookUI.listener invoked", dialog, request, event)  
 -- 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"  
 print( "facebookUI listener, Session Status: " .. event.phase, request )  
 factory.sessionState = event.phase  
 end  
 if ( "session" == event.type ) then  
 if "login" == event.phase then  
  
 print("Login complete, invoking facebook.request", request.path)  
 if request.action then  
 facebook.showDialog( request.action, request.attachment )  
 else  
 facebook.request( request.path, request.method, request.attachment ) -- posting the photo  
 end  
 else  
 print("Login failed: ", event.phase)  
 end  
  
 elseif ( "request" == event.type ) or ( "dialog" == event.type ) then  
 -- event.response is a JSON object from the FB server  
 local response = event.response  
  
 if event.isError then  
 print("Facebook connect error:", json.encode(event))  
 else  
 if "dialog" == event.type and (not(response and string.find(response, "post\_id="))) then  
 print("Dialog cancelled.")  
 if request.onError then  
 request.onError("Canceled")  
 end  
 else  
 print("Facebook Response:",response)  
 local decodedResponse = json.decode(response) or response  
 if decodedResponse and decodedResponse.error then  
 print("Facebook refused request.\n" .. (decodedResponse.error.message or "") )  
 else  
 if request.onResponse then  
 -- invoke callback with decoded json, or plan response if not json encoded  
 request.onResponse(request, decodedResponse)  
 end  
 end  
 end  
 end  
 else  
 print("facebookUI listener - unhandeld event:", event.type)  
 end  
end  
  
function factory.sendMessage( request )  
 -- call the login method of the FB session object, passing in a handler  
 -- to be called upon successful login.  
  
 -- wrap callback to provide context to listener  
 print("invoking facebook.login for ", request.path, request)  
 facebook.login( game.facebookAppId,  
 function(event)  
 listener(request, event)  
 end,  
 request.permissions  
 --{"publish\_stream","user\_photos"}  
 )  
end  

other module:

local fbUI = require( "facebookUI" )  
  
local function getFriendsListener(request, response)  
 local friendsList = response and response.data  
 local contextData = request.contextData  
 -- process the results in friendsList  
end  
  
local function getFriends()  
 local request = {  
 path = "me/friends",  
 attachment = {  
 fields="installed,name,picture.height(90).width(90)"  
 },  
 onResponse = getFriendsListener,  
 onError = function(msg) print("failed", msg) end,  
 contextData = "Other info",  
 }  
 fbUI.sendMessage(request)  
end  

The request table above is just one example, it combines the data to send to facebook with success and error handlers, and can pass additional parameters to the onResponse listener.
It is getting late, I’ve got to go. [import]uid: 120928 topic_id: 34416 reply_id: 142711[/import]

After re-working our code to store the facebook request context globally, our application is now functional on build 1028 (except for the part that attempts to do multiple concurrent facebook requests) I guess I’m going to have to serialize that process and make the user wait.

We have observed a few errors:

Error: HTTP status code: 200  
Facebook connect error: {"isError":true,"type":"request","name":"fbconnect","response":"The operation couldn't be completed. (com.facebook.sdk error 5.)"}  

These have been sporadic, not reproducible, and no pattern has yet been determined. Immediate retry of the same request works.

Thanks [import]uid: 120928 topic_id: 34416 reply_id: 142768[/import]

Facebook error 5 is a general error that’s returned when it couldn’t complete an operation I saw this yesterday when I was testing and the iPad device didn’t have an Internet connection. Your app needs to handle cases when something goes wrong with the connection or talking with the Facebook servers. [import]uid: 7559 topic_id: 34416 reply_id: 142776[/import]

Hey Tom,

I still get Facebook error 5 with my code, which used to work to post a screenshot.

---- \*\*\*\*\*\*\*\*\*\*\* FACEBOOK \*\*\*\*\*\*\*\*\*\*\*\*\* ----  
  
 local function onLoginSuccess()  
  
 local attachment = {  
 message = text[18][language],  
 source = { baseDir=system.DocumentsDirectory, filename="shot.jpg", type="image" }  
 }  
  
 facebook.request( "me/feed", "POST", attachment )  
  
 end  
  
 local function fbListener( event )  
 if event.isError then  
 native.showAlert( "ERROR", event.response, { "OK" } )  
 else  
 if event.type == "session" and event.phase == "login" then  
 -- login was a success; call function  
 onLoginSuccess()  
  
 elseif event.type == "request" then  
 -- this block is executed upon successful facebook.request() call  
  
 native.showAlert( "Success", "The photo has been uploaded.", { "OK" } )  
  
 end  
 end  
 end  
   
 local function postFB(event)  
  
 if event.phase == "began" then   
  
 display.getCurrentStage():setFocus( event.target )  
 event.target.isFocus = true  
  
 elseif event.phase == "moved" then  
  
  
 elseif event.phase == "ended" or event.phase == "cancelled" then  
  
 --\*\* Take screenshot  
 display.save( stillMainMenuGraphicElements[39], "shot.jpg", system.DocumentsDirectory )  
  
 local function waitAndPost()  
 if require("socket").connect("google.com", 80) == nil then  
  
 -- If no internet connection  
  
 else  
  
 facebook.login( fbAppID, fbListener, { "publish\_actions" } )  
  
 end  
 end  
  
 timer.performWithDelay(100, waitAndPost)   
  
 display.getCurrentStage():setFocus( nil )  
 event.target.isFocus = nil  
  
 end  
  
 return true  
end  
  

I did add to the build.settings the following. (However, is it normal to have it once with the “fb” prefix and once without?)

FacebookAppID = "123922354444543",  
  
 CFBundleURLTypes =  
 {  
 {  
 CFBundleURLSchemes =  
 {  
 "fb123922354444543",  
 }  
 }  
 },  
  

Any idea? What am i doing wrong?

Thanks. [import]uid: 100310 topic_id: 34416 reply_id: 142792[/import]

@cebodine, we are looking into your issue to see what we can do to make it work as before. [import]uid: 7559 topic_id: 34416 reply_id: 142794[/import]