Facebook frustrations

Hi everyone.  It seems that Facebook is the thing right now that is frustrating you, the community the most right now.  I’m trying to get a grasp on this bull and wrestle it to the ground for you, but I need your help.  Can you please post the following information for me. 

I can’t promise I can solve all of these because Facebook make somethings just hard.  But there are a lot of threads with plenty of back and forth and want to try and make sure I get the information I think I need.

If you are having problems with facebook, please post in an individual post below:

Platform where you having the problem? iOS or Android (include version number)?

Version of Corona SDK you are using?

What Facebook operation are you trying to do?

What permissions does your activity need?

Post your build.settings file

I may come back and ask for your source code where you’re doing facebook stuff and maybe a screen shot of your Facebook developer settings (I’ll have you email that privately too me)

Thanks

Rob

hej rob, would be really great to have a tutorial on how to intergrate Facebook Scores API into ones Corona Game… If you’ve got time… Thanks you are the best…

https://developers.facebook.com/docs/howtos/scores/

or maybe just an update to this tutorial : http://ideveloper.kodingen.com/2010/facebook-friends-leaderboard/

@ rob,

For me, IOS works exactly the same as it has when I released an app 6 months ago, still works great. ( I am using the GGFacebook found in the Code Share).

Android is the issue.

Android Version : 4.1.2

Corona Version: 1170

Facebook operations: Post simple message AND simple post with an image

Needed permissions: I am not sure honestly, just those to post a message. I don’t look at friend lists or any thing like that.

My build file:

settings = { orientation = { default = "landscapeRight", supported = { "landscapeLeft", "landscapeRight" }, }, plugins = { ["plugin.zip"] = { publisherId = "com.coronalabs", }, }, android = { versionCode = "30", usesPermissions = { "com.android.vending.BILLING", "android.permission.INTERNET", "android.permission.WRITE\_EXTERNAL\_STORAGE", }, }, iphone = { plist = { UIPrerenderedIcon = true, UIApplicationExitsOnSuspend = false, FacebookAppID = "Erased my actual facebook appID", CFBundleURLTypes = { { CFBundleURLSchemes = { "fb Erased my actual facebook appID", } } }, CFBundleIconFile = "Icon.png", CFBundleIconFiles = { "Icon.png" , "Icon@2x.png" , "Icon-72.png" , }, UIAppFonts = { "Baskerville.ttf", "Bubblegum Sans.otf" } }, } }

@rxmarcall have you tried to build the sample app and run it?  You of course have to use your app ID and the com.whatever.whatever that your facebook portal is setup to use.

I haven’t but I will do that tomorrow when I have a few minutes.  My issues were those posted in a few forum topics about issues of having the facebook app installed on the device and login issues.

Anyways, I will report back with my results.

Are you using a debug.keystore or a release.keystore?

I was using a release.keystore.  I had been working on an update to an already LIVE app, so I was using the same keystore that I had launched the app with.

Hi Rob,

I thought I’d chime in and try to share with you and others what I think is the status with Facebook right now.  There are a number of similar but distinct issues, a fair bit of misinformation (partly spread, unfortunately, by me in this thread: http://forums.coronalabs.com/topic/37400-facebook-login-flow-on-android-broken-since-daily-build-1141/#entry195068), and of course some situations where blame is being placed on Facebook when it’s actually bugs in our own code.

For me, the bottom line is that Facebook is working fine (starting in Build 1158).  I’ve been able to integrate everything I was looking to do, which includes basic and publishing permissions on both iOS and Android with a successful and user-friendly login flow (regardless of whether or not the Facebook app is installed), and graceful handling of situations when the app is deauthorized / permissions are rescinded.  But this wasn’t without some work.  I ended up writing a module that wraps the Corona facebook API to enable some critical additional functionality, described more below.

But first, here’s what I think are the challenges that folks are facing:

  • Requesting Additional Permissions

    • By requesting additional permissions, I mean situations where the app asks for certain permissions at one point, and later needs to ask for more permissions.  There are two main use cases for this:
    1. As a best practice, apps should only request permissions from users as and when the app actually needs them.  Many users will be put off if they try to take a simple facebook action, and the app asks for the kitchen sink of permissions that it obviously doesn’t need at that point
    2. In certain cases (described more below), Facebook is now requiring that apps cannot even request extended permissions, such as publish_actions, until they’ve first been granted some basic reading permissions like basic_info.  Thus, in these cases, the first call to facebook.login() cannot include an extended permission.  But if the app needs it, then there needs to be a way to request additional permissions later
    • The problem is, while the facebook.login() API lets us specify what permissions to ask for, the API doesn’t appear to provide an obvious way to request additional permissions after an initial successful login.  The way to do it is to call facebook.logout() and immediately call facebook.login() with the additional needed permissions.  But this isn’t obvious to many in the community, and it feels awkward (largely because it doesn’t jive with the names ‘login’ and ‘logout’).
  • Changes to Android Login Flow

    • Build 1141 made a critical update to Corona’s Facebook integration on Android.  Prior to that Build, I suspect that Corona’s integration worked only through webViews, with no linkage to the Facebook app.  Starting in Build 1141, Corona began using the Facebook app for login flow, if it’s installed.  This had two confusing consequences:
  1. First, whereas previously the login dialogs would appear in a nice looking webView, now they appear in a native alert (which don’t offer the user an option to change the privacy settings of extended permissions).  This looked like a bug to me, hence the thread I mentioned above, but in fact, it’s how Facebook’s app for Android handles the login flow (see screenshots here: https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/#overview).
  2. Second, the Facebook app for Android requires that an app have basic reading permissions, such as basic_info, before requesting extended publishing permissions, such as publish_actions.  The webView flow doesn’t require this.  Thus, before Build 1141, a call like facebook.login(appId, listener, {“publish_actions”} would work as the first call to facebook.login(), but starting in Build 1141, it would fail.
  • Facebook Dialog Response
  • "Do if Permitted, Otherwise Get Permission"
    • The Corona facebook API doesn’t have a built-in “do if permitted, otherwise get permission” mechanism.  By this I mean a mechanism that only performs a facebook request if the user is logged in and the app has the necessary permission to complete the request.  If the user isn’t logged in or doesn’t have the necessary permissions, the mechanism would first login them in or request the permissions, and if that succeeds, only then perform the request.
    • This is a pretty important piece of functionality that requires keeping track of the permissions the app has been granted and knowing what permissions are required for a request.  It’s one of the elements I had to build into my own wrapper module
  • Callbacks Per Action
    • ​The Corona facebook API doesn’t have a mechanism to register a callback for each call to the API.  Instead, we have to provide a listener to facebook.login() and use that listener for all subsequent calls to the facebook API.  This creates challenges to many users, including:
      1. How to implement a “do if permitted, otherwise get permission” mechanism
      2. How to handle the facebook.logout() / facebook.login() strategy mentioned above to get additional permissions after an initial login

I think we’re seeing a lot of issues come up in the forums largely because dealing with all of these issues isn’t trivial.

I’ve seen some other threads citing issues with uploading pictures to Facebook, but that’s not something I do, so I don’t know if there’s a real problem there or if it’s just a symptom of one of the above points.

I hope this (admittedly long!) post helps bring some clarity to the situation.

  • Andrew

Andrew, thank you for that very detailed response.  It’s really helpful for me to get my head wrapped around some of these changes.  I’ve shared it with Engineering while they explore it from the their perspective.  If it’s okay with you, can I use some of this in the next Facebook blog post?  I’m going to try and work through the login problems and get that scaled down to something that will work for more people.

Thanks for this!

Rob

Hi Rob,

No problem, glad it was helpful!  Definitely feel free to incorporate it in your blog post.  I’m also happy to chat more on this thread or offline as you explore the situation yourself.

A few additional tidbits I neglected to mention that may be useful:

  • In their October 2013 breaking changes (https://developers.facebook.com/blog/post/2013/06/26/october-2013-platform-changes/) Facebook noted that apps will be required to use the Facebook SDKs for login.  I’m quite sure that’s what Corona does already, but it might still be worth mentioning it in the blog post to preempt any doubts in the community
  • On my point above that in certain cases (namely, on Android when the Facebook app is installed), Facebook is not allowing apps to request extended permissions, such as publish_actions, until they’ve first been granted some basic permissions like basic_info, I wanted to mention that it’s hard to find the documentation from Facebook to support this behavior.  It’s just something I’ve noticed in practice.  However, there are some comments in Facebook’s documentation that seem to allude to it:
    • On Android, this page (https://developers.facebook.com/docs/howtos/androidsdk/3.0/native-login/) says that “Apps must have a basic connection to a user’s Facebook account to ask for permission to post on the user’s behalf or to read other fields from the user’s timeline or their friends’ timelines”.  Notice how in step 1, the only permission requested is basic_info, and only in later steps do they request additional permissions
    • On iOS, this page (https://developers.facebook.com/docs/technical-guides/iossdk/login/) makes essentially the same comment that “Apps must have a basic connection to a user’s Facebook account before asking for permission to post on the person’s behalf or to read other fields from the person’s timeline.”  Again, if you follow their example code, you’ll see they request basic_info before requesting additional permissions
  • What’s strange is that, despite these comments in Facebook’s documentation suggesting it’s necessary on both iOS and Android, in practice I only encountered an issue on Android when the Facebook app is installed.  In other words, if my first ever call to facebook.login() asks for publish_actions permissions, it works fine on Android without the Facebook app and also on iOS.  It’s only on Android with the Facebook app installed that I’ve found it necessary for the first call to facebook.login() to request only basic_info permissions, and when that succeeds, to call facebook.logout() and then facebook.login() for publish_actions permissions

I should also mention that all of my Android testing is done on a device running Android 2.2.

  • Andrew

Have you looked at using the facebook.showDialog(“login”) API call to request additional permissions?  I’ve not had a chance to really try it yet, but it seems to me that’s might be the desired route to the extended permissions.

Hi Rob,

Actually I didn’t even realize there was such a dialog, but it’s a really excellent suggestion, and it’s probably the intended mechanism for requesting additional permissions.  Facebook’s documentation itself says that “You also use it [the login dialog] when you need people to grant additional permissions to your app.”

I haven’t tried it yet, but I suspect from a user experience perspective, calling facebook.logout() followed by facebook.login() will look the same as opening the login dialog using facebook.showDialog(“login”).  But clearly the latter is a much cleaner solution.  I’ll be interested in seeing what the response to the listener is like when I give it a try.

If this turns out to be the right solution, it’ll be well worth publicizing in the blog post and in the Corona API documentation!

  • Andrew

Hi Rob,

I’ve given facebook.showDialog(“login”) a try, but I’m not able to get it to work.  I tested on an iPhone 5, iOS 6.1.3, with the Facebook app installed, using the simple test case below.  (Naturally, this was embedded in a project with the appropriate build.settings and a real Facebook app ID.)

[lua]

local listener = function(event)

   print_r(event)

end

facebook.login(facebookAppID, listener)

– This timer is meant to simulate the use case where the user is already logged in, and sometime later we need to get additional permissions from them

timer.performWithDelay(4000,

    function()

       facebook.showDialog(“login”)

    end

)

[/lua]

The call to facebook.login() works fine, switching to the Facebook app and presenting the basic info permission screen.  But the call to facebook.showDialog() doesn’t work.  Instead of opening the Facebook app, I get a Facebook webView with the message: “The page you requested was not found”.  I’ve tried some variations with additional parameters based on Facebook’s documentation (https://developers.facebook.com/docs/reference/dialogs/oauth/), but the behavior was the same:

- facebook.showDialog(“login”, {scope=“read_requests”})

  • facebook.showDialog(“login”, {client_id=facebookAppID, scope=“read_requests”})

  • facebook.showDialog(“BLAHBLAH”)

In all cases, after the webView is dismissed, the listener gets an event with type=“dialog”, name=“fbconnect”, didComplete=false, isError=false, response="".

By contrast, launching a different dialog, such as facebook.showDialog(“appRequests”, {message=“This is my message”, title=“This is my title”}), worked fine.

Since I got the same behavior whether I used “login” or “BLAHBLAH”, it suggests that the string “login” may not be the right value, though I can’t imagine or find any documentation what else it could be.  It’s also possible that Corona’s integration with the Facebook SDK simply isn’t working for that particular dialog, since it’s clearly working for “apprequests”.

  • Andrew

Can anyone actually logout with facebook.logout()?  I have a multiuser app and no matter what, the first user remains logged in.  I need to log them out before the next user attempts to use the app.

@mgartner I suspect that your app is probably logging out just fine, but the Facebook app is remaining logged in with the user it was last logged in with and it remembers the permission requests.  Are you changing who’s logged into that that app between runs of your app?

That’s the problem. It’s a public kiosk application.  I need the FB app to be logged out as well.  I can’t have the next user log the previous user out.  My previous mobile experience with the FB SDK was with Phonegap, and that was able to log the user out of the FB app.  There’s native iOS apps that also log out of the FB app too, so I know it must be possible.

Seems like the solution is to not have the facebook app installed, and let it work through the webView.  But then again, once you’re logged in to the browser, it might keep you logged in.

Yes I tried that as well, it does.  So what does facebook.logout() actually do?  Am I crazy for thinking it should log you out and let the next person log in?

When your app logs into facebook, an auth token is generated that indicates your app is logged into facebook.  What facebook.logout() does is log your app out of facebook’s connect system. It has no effect on a user being logged into facebook. 

Ok. So seeing that it is possible in native iOS as well as phonegap apps, there has to be a way to do it in Corona. I have a commercial product that’s 99% ready for release and is being held up by this one issue. Is there any way to address this with the development team? I’d gladly pay for the support option for direct communication if it is possible to get this implemented.