Facebook 3.1.1 SDK breaks A LOT

Hey, Antony, I updated my FB implementation as per haakon’s note, and it works fine for me:

  1. When I just log my user in to FB, I do this, and this seems to work fine. Even though I’m pulling down the user’s FB data in the process, it didn’t cause any error. I wonder why. Maybe I should test this again just in case:
    facebook.login( myAppID, myFBListener, { “email” } )

Edit: I did a fresh install (after wiping my device), and it turns out that simply logging into FB with permission works fine. However, if I proceed to step 2 below (pulling down the FB friends list), it fails. If I login with permission first, and then call facebook.logout() before proceeding to step 2, it works fine. So, it seems like the options I have is to either log user out immediately after I log them in with permission, or not require permission at all when user connects with FB during the registration process…

  1. When I need to pull down FB friends list, I do this, and it works like a charm:
    facebook.login( myAppID, myFBListener)

  2. When I need to POST a message on FB wall, I do this, and it works like a charm:
    facebook.login( myAppID, myFBListener, {“publish_action”})

  3. By the way, I was also able to POST a message even when I removed the permission (but I decided to keep the permission for my app):
    facebook.login( myAppID, myFBListener)

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

I hate to add more to this saga, but I can’t help myself. I had to test what would happen if I didn’t call facebook.logout() after calling facebook.login( myAppID, myFBListener, { “email” } ) to fetch the user login credential – on both build 991 and 1008.

The result was identical. It surprised me. I thought the issue was introduced when FB SDK was updated, but it looks like that was not the root cause of the issue.


Edit: I was testing on wrong build. I needed to test on 990 and 1008 to see the difference. And the result was not identical. It was different like night and day. The case 4 result detailed below is with 1008 which incorporated updated FB SDK. My post #46 shows the case 4 result with 990 that uses un-updated FB SDK.

I followed the CASE 2 procedure – meaning, I did not intentionally cancel the login process because I really wanted the FB login process to work:

CASE 4: (modified version of CASE 2 with a freshly wiped device with a new user)

1 (scene A): facebook.login( myAppID, myFBListener, { “email” } )
* User skips the FB Connect button

2 (scene B): facebook.login( myAppID, myFBListener, { “email” } )
* This scene has FB Connect button this time (instead of FB Friend button).
* FB Connect button brings up FB Log in screen
* User enters FB email address and FB password
* FB permission screen with email as part of the app requirement come up
* User taps on Log in button
* Login process completes without a hitch and automatically triggers facebook.request( “me” ) in step 3

3 (scene B): facebook.request( “me” )
* Fetches login credential perfectly
* Do not call facebook.logout() here – I commented it out from the script
* Saves login credential for the app
* Upon successful save, automatically triggers facebook.login( myAppID, myFBListener ) in step 4

4 (scene B): facebook.login( myAppID, myFBListener )
* Immediately after the login process completes, FB permission screen comes up (stating that the user has already authorized this app)
* User okays it
* Then the screen goes back to my app, while I also get Error: HTTP status code: 400
* My app screen says Facebook login failed.
* User closes the login fail notice.

5 (scene B): facebook.login( myAppID, myFBListener )
* The screen updates to show FB Friends button.
* Tapping on it launches facebook.login( myAppID, myFBListener )
* Which brings up FB permission screen again (stating that the user has already authorized this app)
* Tapping okay triggers Error: HTTP status code: 400 again.
* My app screen says Facebook login failed.
* User closes the login fail notice.
* And this step 5 repeats itself over and over.
* All the other parts of the app appears to behave and function as expected. I just can’t go anywhere beyond this step 5 with FB feature of the app.
* So I killed the app and relaunched it.

6 (scene B) – tapping on FB Friends button brings up friends list (the buttons) without asking for FB permission, and it works smoothly without a hitch.

So it appears, adding the facebook.logout() was absolutely necessary to avoid the error 400. I think it was haakon who identified and posted the need to add facebook.logout() in some other thread somewhere – thank you (and if it was someone else, whoever it was, thank you.) It was frustrating process, but this really got me trapping all sorts of potential errors that could crash my app.

Also, you wouldn’t encounter this issue if you don’t need the login to require email as part of the parameter (and if so, you may not need to call facebook.logout). In my app, under this specific path user takes, it is necessary.

Anyhow, I hope this test result helps others who come across the same error.

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

Hi Naomi,

This page was quite helpful
https://developers.facebook.com/docs/howtos/login/handling-revoked-permissions/
They basically say, only ask for permissions as as you need them - and hint you need to go through the relogin process.

So in my testing I did this (although I am using Bob Dickinson’s FB helper - so my calls are slightly different)

1: facebook.login( myAppID, myFBListener, { “email” } )
2: Get friends - Works fine
3: facebook.login( myAppID, myFBListener, { “publish_action” } )
4: post to users wall

Step 3 failed for me, as it never actually prompted the user to authorise the new permission (yes I had cleared the authorisation in FB) and so step 4 failed with an error.

Maybe you do need to logout and in again as you have suggested - but to be honest I really wanted to get the next update to my app out so I reverted back to build 990, submitted the app version and decided to re-look at this issue when I need to do the next update!

Antony [import]uid: 169392 topic_id: 34416 reply_id: 139823[/import]

OMG, Rob, thanks for pointing that out. How terrible. I totally misread the earlier post. Should not have downloaded the 991 at all. Urrrrrrgh. This is turning into a nightmare. I’ll download 990. I guess I have to go through this whole bloody test process again (if I am to follow through with this pain-in-the-neck test procedure.)

Edit: OMG, pardon my language above. I was so exasperated that I couldn’t help myself.

Lo and behold. 990 DID NOT THROW ANY ERRORS! And it worked soooo smoothly that I can cry.

So, it was the Facebook SDK upgrade that caused this issue after all. And with the 990, I don’t need to call facebook.logout at all. I hope Corona Labs can implement the fix.

Anyhow, please see my test case below.

Naomi

CASE 4: (app built with 990, test process is the modified version of CASE 2 with a freshly wiped device with a new user)

1 (scene A): facebook.login( myAppID, myFBListener, { “email” } )
* User skips the FB Connect button

2 (scene B): facebook.login( myAppID, myFBListener, { “email” } )
* This scene has FB Connect button this time (instead of FB Friend button).
* FB Connect button brings up FB Log in screen
* User enters FB email address and FB password
* FB permission screen with email as part of the app requirement come up
* User taps on Log in button
* Login process completes without a hitch and automatically triggers facebook.request( “me” ) in step 3

3 (scene B): facebook.request( “me” )
* Fetches login credential perfectly
* Do not call facebook.logout() here – I commented it out from the script
* Saves login credential for the app
* Upon successful save, automatically triggers facebook.login( myAppID, myFBListener ) in step 4

4 (scene B): facebook.login( myAppID, myFBListener )
* Behind the scene, it calls facebook.login( myAppID, myFBListener ), which triggers facebook.request( “me/friends” ) in step 5

5 (scene B): facebook.request( “me/friends” )
* Fetches friends list perfectly fine.
* Loads the list of friends without a hitch.
* Do not call facebook.logout() here – I commented it out from the script

  1. (scene B): facebook.login( myAppID, myPostListener, { “publish_actions” } )
    * Each FB friend that was fetched in step 5 becomes a friend button
    * If the friend is not already registered with the app, tapping on the friend’s button triggers facebook.showDialog( “feed”, attachment ) in step 7

7 (scene B): facebook.showDialog( “feed”, attachment )
* FB dialog pops up
* Tapping on Share button on FB dialog makes the post successfully
* Tapping on another friend’s button brings up FB dialog (without permission screen this time)
* ALL WORKS EXTREMELY WELL.

THE USER HAD TO AUTHORIZE THE APP ONLY ONCE! PERFECT.

P.S. Just to be clear, as far as the user is concerned, all he/she sees is the initial FB login screen. Once the user logs in, the next thing he/she sees is the app screen with rows of friends’ names. If a friend is already registered with the app, tapping on the friend initiates a match game for this app. If a friend is not already registered, tapping on the friend brings up the FB dialog (without pausing to ask for the user’s FB permission.) Works really like a charm when built with 990.
[import]uid: 67217 topic_id: 34416 reply_id: 140430[/import]

Naomi,

Thank you for all your testing and confirmation. I also verified that the error doesn’t occur in build 990 but does happen in build 1013 so it’s related to the new Facebook SDK or Corona’s integration.

From my testing and reading, it looks like Facebook made some changes in the Login process. I determined that the error is coming from the permissions used in the Login. I can trigger the error every time by logging in and getting User info or posting a message. If I then log out and log back in, the error will happen on the first or second Facebook access. If I remove the permissions from the Logon, I never see the error. Changing to a different permission doesn’t change anything.

Logging out and back in, is the key to when I saw the error happen. Internally the permissions are only sent to Facebook when you call Login AND the session is not active (e.g., logged out).

It seems that Facebook wants you to set permissions the first time you log in a user and not for every log in after that. You would need to add back permissions if the user cancelled your App’s access or needed to add additional permissions. (You must log out and log back in to set new/additional permissions.)

Under the hood there is no need to call the FB Login API for every command, except when your app is started or you determined that the user has logged out. You must call the Login API when the app first starts because that’s what initializes the FB Connect module. Calling the Login API (without permissions) does no harm because it only does an actual FB login if it finds the session isn’t active (e.g., the user is not logged in).

Can you try implementing the above sequence (not adding any permissions to the Login, except for the first time) to see if that works for you with the latest Corona build?

I’m still looking at this, but I’m not sure there is anything we can fix internally. This may be a change in the way Facebook wants to handle Login, so changing how we call the interface may be all that’s needed to keep the error from happening.

One other note about Facebook errors. The Corona sample code will have a Lua runtime error if FB returns an error. That’s because it’s treating the event.response as a json table when it’s really an error string. I posted the fix in comment #41.

I should note that we are using the latest Facebook SDK without modification. We add code to interface Corona to their SDK but we can’t troubleshoot or debug issues that may be in their code. For most third party libraries that are used in Corona, if we find bugs we try to report them but need to wait for the author to fix them. I don’t know if that’s the case with Facebook, but I’m sure there are bound to be bugs/errors (as found in all code).

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

Hi Tom, thank you for the detailed note. I appreciate you taking the time to explain. From what you noted, it sounds like I should further edit my code to achieve the behavior I want. I’ll give it a shot and see if I can make my app built with 1008 to flow the same way as it does with 990. I will report back once I have a chance to work on it.

Thanks again!

Naomi

Edit: BTW, I will download 1013 just to make sure I’m working with the same build. [import]uid: 67217 topic_id: 34416 reply_id: 140545[/import]

Hey, Antony, after I wiped my device and clean slated FB test user account, I’m getting the similar result as yours.

It was working fine (as I described in post #18) yesterday. But today, after I clean slated my test device and FB test user account, posting to user’s friend’s wall completely fails with Error: HTTP status code: 403

1: facebook.login( myAppID, myFBListener, { “email” } ) - works fine
2: facebook.request( “me/friends” ) - works fine (and fetches friends list)
3: facebook.login( myAppID, myPostListener, { “publish_actions” } ) - logs in fine
4: facebook.request( feedMyFriend, “POST”, attachment ) - fails with HTTP error

The code for step 4 used to work (it worked yesterday), but now it doesn’t. Ugh.

Naomi

Edit 1: I went back and looked up FB Graph API:
https://developers.facebook.com/docs/reference/api/publishing/
Regarding the /PROFILE_ID/feed method (for publishing a new post on the given profile’s feed/wall), it says Note that this feature will be removed soon.

Yikes, maybe that’s why it’s not working anymore. Urrrrrgh. How frustrating.

Edit 2: Here’s a relevant post by @george18 (thank you george18):
http://developer.coronalabs.com/forum/2012/11/22/has-facebook-posting-stopped-working-last-week#comment-132107

Sounds like I need to invoke feed dialog… [import]uid: 67217 topic_id: 34416 reply_id: 139872[/import]

I wonder if that only applies to the new SDK? It’s currently working fine in my live app which uses the old one.

Either way I guess it’s time to make the change and get ready to submit to apple for when the feature does go away. It’s frustrating as I have only just submitted the latest version to Apple! [import]uid: 169392 topic_id: 34416 reply_id: 139973[/import]

So I updated my script from facebook.request to facebook.showDialog( “feed”, attachment ), and it did the job very well. Ahhhh, what a pleasure it is to work with Facebook.

Naomi

P.S. And here’s a great tip from AlanPlantPot about what showDialog returns:

http://developer.coronalabs.com/forum/2012/12/06/how-can-i-post-text-facebook-feed-dialog#comment-134151 [import]uid: 67217 topic_id: 34416 reply_id: 139974[/import]

Naomi,

I’m glad you discovered that yourself. It was on my GTD today to make a comment about that possibility. The dialog working is not weird at all. It needs no permissions, since what is posted is user controlled - not server or app controlled. [import]uid: 21746 topic_id: 34416 reply_id: 139975[/import]

Thanks, Haakon. I really wanted the facebook.request to work, especially since we can pre-determine what gets posted.

With facebook.showDialog, I would be happier if we could pre-fill the text message that the user could send. I wouldn’t mind the user editing it. It’s just that pre-filling would make it so much better for the app, and makes it so much easier for the user too. But from Facebook API page, it doesn’t look like there’s any way they would allow pre-filling the message:

https://developers.facebook.com/docs/reference/dialogs/feed/

If I’m mistaken, please let me know.

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

Naomi, I have not been able to find a way… and all I have read says you can’t do that anymore. Instead I am using the name, caption and description fields to get the message across.

One issue I am now having, is that my previous link would cause the device to launch the app store or app. Now that I am using the feed dialog, it causes facebook to load the app page. Any idea how I get around that, I don’t want to give users an extra step?

This is my current URL, perhaps there is another one I should use?
https://www.facebook.com/apps/application.php?id=267797749998454

Antony [import]uid: 169392 topic_id: 34416 reply_id: 139997[/import]

I am seeing memory leaks every time the Sample Code makes a Facebook Request. The ones below and some other similar ones. Should I post a bug report? Will Apple reject apps because of this leak?

FBRequest (64 Bytes) UIKit forwardTouchMethod  
\_\_NSCFString (64 Bytes) Foundation -[NSString initWithUTF8String:]  

[import]uid: 73434 topic_id: 34416 reply_id: 140568[/import]

Damned! So much time wasted today.
Thanks to all to share your experiences, it’s less time than it could have been.

I do too have the “The operation couldn’t be completed. (com.facebook.sdk error 5.)”, even though my code used to seem perfectly fine before. I find extremely surprising that Ansca is not on top of this issue (there are more and more tutorials on the corona website which are just not working).

Anyway, if i understand properly, facebook.request to POST an image on a facebook wall doesn’t work anymore.

facebook.showDialog should be used, but it seems it can’t upload a picture from the device (actually i could not even get it to post a picture from a website).

So, basically, is there still an option to post a picture (like a display.save) to the user’s wall or no?

Dim
[import]uid: 100310 topic_id: 34416 reply_id: 140113[/import]

Hey, haakon, if you are annoyed by me making giant posts under this thread, please let me know, and I’ll move it to a new thread. (I think it’s related, and so I think it’s okay, but I never know how others feel & think, and I have no intention of offending you.)

@Tom, I was thinking of completely redoing my FB related code so that there’s only a single instance of facebook.login call after the app is launched. If I implement it that way, my app wouldn’t make facebook.login call twice. It will make the facebook.login call only if the app is killed and restarted (or when the user taps on the FB connect button the first time.) But from what you posted on #47, I’m not sure if it would make any difference. With both CASE 5 and CASE 6, I make facebook.login call with permission only once (at the time of signing in and authorizing the app.) All other facebook.login calls do not include permission (because every possible permissions required for the app is now included in the very first facebook.login call.) The app also never logs out of FB in both CASE 5 and CASE 6. So my finding is different from what you found to be the issue. So I’m wondering if it’s worth the trouble removing second and subsequent facebook.login calls.

Besides, how would the app know if/when user deauthorizes the app from his/her FB account or logs out of FB when these things are done outside the app. If I’m not calling facebook.login, but just facebook.request, I’m assuming that the event.type would only return “request” and not “session”… Does facebook.request return event.phase with “loginFailed” or “loginCancelled” too? If it does, I could work with this and see if single login call would solve all my woes.

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

Wow. No kidding. The well placed facebook.logout actually solved the CASE 6. Maybe it will solve CASE 5 too. Is this what you did, haakon, to work this out? I do remember seeing a post somewhere about the key to solving Facebook problem is the use of facebook.logout. The problem was, I added the facebook.logout everywhere early on, which wildly exacerbated my problem and complicated the debug process for me.

Here’s the solution I found for my app:

  1. add facebook.logout only inside if-statement of an event.phase ~= “login”

  2. call facebook.login with permissions only once after the app is launched
    Note: actually, with my app, I might be call facebook.login with permissions only once per device. Once a user give permission on a given device, until the device is wiped, I might not be calling the login with permission. I need to investigate a bit more before I implement this on all FB related calls, but I suppose it’s enough info for anyone who might be seeking solution here, so I won’t be updating this note.

  3. after facebook.login with permissions is called once (and after the user permits the app’s use of Facebook access), call facebook.login without permission

I think that was all it took. I’m not seeing the problem Tom mentions in his post #47, so who knows, my app might come across that issue (hopefully not, though.) I can also still think of other paths the user may take that could possibly bring back the Error 400 (such as de-authorizing/removing the app directly from the user’s Facebook account while the app is still in suspend mode), but perhaps that’s an edge case I can live with (and perhaps it won’t even cause error 400, who knows – I’m too tired to test every possible case that I can think relating to my FB fiasco at this point.) I’m going to move on and work on finishing up my app (which is way late than I hoped.)

Tom or anyone else who is dealing with this error, please let me know if you find other solution(s). I would also like to hear if there are other error case(s) that cannot be solved with the solution I employed. It can only help us get our Facebook components working smoothly with the updated Facebook SDK.

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

We’ve had an outstanding bug request on this new Facebook API issue since January 9th and can’t get anybody to respond to us. We provided sample code (their sample API code) to show the bug and they simply won’t respond to us.

We can’t drop back to build 990 because the custom notification tag issue was fixed in 996 and that is a show stopper too.

bug 20096 has been open with no response. http://bugs.anscamobile.com/default.asp?20096_d4djkrj5jbbsen14

Is anybody at Corona still listening to their clients?!?!? [import]uid: 120928 topic_id: 34416 reply_id: 140265[/import]

We are looking at the issue now. [import]uid: 7559 topic_id: 34416 reply_id: 140270[/import]

Glad to hear Corona Labs is looking at the bug @cebodine reported. When testing all possible FB login routes (and login cancel routes) that users could make in my project, I found the very similar failure that @cebodine noted in the report, and I have not been able to sort out workaround short of killing the app – and yes, once killed, I don’t see the FB failure again. Very frustrating.

Edit: BTW, when it fails, I now get this error: Error: HTTP status code: 400

I’m using daily build 1008 (but plan on updating to the latest soon – perhaps after the FB related fixes get in.)

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

From our point of view only one user filed a bug report with recent Facebook issues. Generally when there is a major problem, we receive reports from multiple users reporting the problem. That’s generally a good gauge of bug or operator error. We are looking into this and will report back what we find.

-Tom [import]uid: 7559 topic_id: 34416 reply_id: 140282[/import]