[Resolved] Facebook sign in works via mobile browser but not if Facebook App is installed

Facebook integration built into our app was mostly working fine until I tested it on a phone with the facebook app installed then login simply fails.

I can repeat this issue really easily:
FAILS:
Install facebook app and click the facebook login button from our home screen, the phone switches to the facebook app, appears to do a bit of thinking then switches back to our app but the event.phase is login_failed.

SUCEEDS:
Uninstall facebook app and click the facebook login button from our home screen, the phone switches to the browser at the facebook page, which either makes you login and do the permission thing or else says “you’ve already given permission etc”, either way after clicking okay it switches back to our app and reports successful login which subsequently allows posts and friends retrieval etc.

I initially, naturally, thought it was our code but subsequently took the code from the documentation and experienced the same symptoms. I then modified it slightly as below to show some alerts with debug info (the function, “fbButtonTapped” is attached to the button tap event and I replaced the fb app id with the correct one).

[lua]local facebook = require “facebook”
– listener for “fbconnect” events
local function listener( event )
if ( “session” == event.type ) then
– upon successful login, request list of friends
if ( “login” == event.phase ) then
native.showAlert(“FB DBUG”, “login success”, {“OK”})
facebook.request( “me/friends” )
else
native.showAlert(“FB DBUG”, “login failed! RESPONSE: “…event.response…”|| PHASE:”…event.phase, {“OK”})
end
elseif ( “request” == event.type ) then
– event.response is a JSON object from the FB server
local response = event.response
native.showAlert( “FB DBUG”, response, {“OK”} )
end
end

function fbButtonTapped()
– FacebookController:instance():showStatus(self)
– first argument is the app id that you get from Facebook
facebook.login( “1234567890”, listener, {“publish_stream”} )[/lua]

Without the facebook app installed I get the login success alert and the json for the friends list alert.
With the facebook app installed I get the login failed alert with nothing in the event response.

Can any one please provide any suggestions as I am at a total loss… [import]uid: 60648 topic_id: 28437 reply_id: 328437[/import]

Do you have this:

CFBungleURLTypes =   
{   
 {  
 CFBungleURLSchemes =  
 {  
 "fbXXXXXXXXXXXXXXX",  
 }  
 }  
},  

in your build.settings where “fbXXXXXXXXXXXXXX” is the string “fb” plus your FaceBook APP ID?

This is how the FB app knows to call back to your app when it’s done authorizing you.

[import]uid: 19626 topic_id: 28437 reply_id: 114783[/import]

I have the EXACTLY same problem right now!

I`ve passed 2 nights brainstorming the FB integration at all (I even have removed and re-created the app on FB), but not seems to work!!

PS: By now I`ve just "abandoned"it at all. :[

PS: I`ve implemented the same thing before on 2 apps, but now, it cannot seems to work.
Rodrigo.

EDIT : @rob, if I can answer you, I have to say that Ive done that and also removed that from the build.setting **a thousand times** or close to it. BTW, I think Ive tried all I could imagine about FB SSO. BTW I think it`s a FB app problem, because before with the same implementation all were working nice. Just weird. :S

Thanks for posting. [import]uid: 89165 topic_id: 28437 reply_id: 114784[/import]

I have had this same problem before, and it was always due to something wrong in the build of Corona I was using, so try an older / newer build and see what happens!

thomas [import]uid: 70134 topic_id: 28437 reply_id: 114787[/import]

@thomas,

I appreciate your “tip” as much as @robs input too. BTW Ive tried also changing Corona builds (that by now I`ve tried with .840, .843 and .846). Maybe I should try other ones as well… :S
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 28437 reply_id: 114788[/import]

Well I have it working in two apps and if you read this blog post:

http://www.coronalabs.com/blog/2012/01/04/implementing-facebook-single-sign-on/

note: For iOS apps, in the ‘Native iOS App’ section, it is important that the iOS Bundle ID is the same as the provisioning profile that you’ll use to build your app in Corona. Also ensure that you enter a valid iTunes App ID in the iPhone App Store ID section. When you add your app to the iTunesConnect portal, your app will be assigned an “App Store ID” (even prior to uploading the binary).

note: By default, UIApplicationExitsOnSuspend is set to false if you don’t include it, but I included it in the example as a reminder that it must be set to false for Facebook single sign-on to work properly.

and again: When you call facebook.login(), if the Facebook app is installed on the device, it will come up and ask to authorize your app (if it hadn’t been previously authorized). If the Facebook app is not installed, the device’s web browser will come up. When the user finishes logging in/authorizing, your app should be brought back up again (which is why UIApplicationExitsOnSuspend needs to be false).

then it should work for you. [import]uid: 19626 topic_id: 28437 reply_id: 114790[/import]

Robs advice is spot on, you need to ensure your building with the same provisioning profile that you registered to use on the facebook developers site. [import]uid: 84637 topic_id: 28437 reply_id: 114792[/import]

@rob , firstly, much appreciated!

So, regarding all the important points youve passed above, Ill let my feedback based on it, lets see:

• Ensure that you enter a valid iTunes App ID in the iPhone App Store ID section. When you add your app to the iTunesConnect portal, your app will be assigned an “App Store ID” (even prior to uploading the binary).

–> So, about that Ive done all as you said as well. Ive used a valid iTunnes App ID (from one of my apps live on app store). Ive tried to use the own apps iTunnes App ID as well but using that Facebook tells me that as my app isn`t LIVE on AppStore yet so it cannot be used regarding the FB SSO dashboard. :S
• By default, UIApplicationExitsOnSuspend is set to false if you don’t include it, but I included it in the example as a reminder that it must be set to false for Facebook single sign-on to work properly.

–> Sure! My app does have that key - UIApplicationExitsOnSuspend = false - set into the build.settings file as well.
• When you call facebook.login(), if the Facebook app is installed on the device, it will come up and ask to authorize your app (if it hadn’t been previously authorized).

–> Right! But what happens here is that it sure does come up with the Facebook app (as I`ve it installed), BUT instead of it giving me the “screen” asking “authorization” for the app to use FB, it will just calls the Facebook app and suddenly (like a flash), “come back” to my app telling me (debug) that the login was failed ([lua]event.phase == loginFailed[/lua]) and no any more “reasons” anyway. :frowning:
• If the Facebook app is not installed, the device’s web browser will come up. When the user finishes logging in/authorizing, your app should be brought back up again (which is why UIApplicationExitsOnSuspend needs to be false).

–> YES! This one is the one that really happens for me here. IF I delete the Facebook app, all you said above is what happens normally. It asks permissions as well and does all the “procedures” just normal and even really get the post into FB timeline. The problem here is that I wouldn`t ask my users to delete their Facebook apps in order to get the post from my app posted to their FB timelines, huh! :wink:

PS: For iOS apps, in the ‘Native iOS App’ section, it is important that the iOS Bundle ID is the same as the provisioning profile that you’ll use to build your app in Corona.

–> This one is the one that I am/was afraid of! Because I just use my *Team Development Profile (when developing my apps) and I almost never go through the iTC Provisioning Portal to be setting-up “Ad-Hoc” profiles. SO, here comes my “doubt”: would I be in this FB SSO trouble only because of an AdHoc *cheet* profile??! :S BTW Im 95% sure that on the previous 2 apps that Ive implemented this FB SSO thing I`ve used again and as always the *Team Development Profile. I think you got my mind twisted right now Rob. :slight_smile:
Thanks for the detailed feedback.
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 28437 reply_id: 114794[/import]

I never use the Team Development Profile.

Instead I created a Provisioning Profile that I use for testing.

com.mydomain.test

or something similar. I use this to build on when I’m testing an app. I have both an AdHoc and a Development version, but frankly I only use the AdHoc until I need to run Instruments to test for memory leaks. Now the draw back to this is I can only have one of these test apps on my device at a time, but it solves the issues of having a specific bundle ID for things like Facebook.

But your FB-SSO isn’t going to work with the team profile. [import]uid: 19626 topic_id: 28437 reply_id: 114830[/import]

This is my build.settings file:
[lua]settings =
{
orientation =
{
default = “portrait”,
},
iphone =
{
plist =
{
–UIPrerenderedIcon = true, – this doesn’t seem to have any effect
CFBundleIconFile = “Icon.png”,
CFBundleIconFiles = {
“Icon.png” ,
“Icon@2x.png” ,
“Icon-72.png” ,
},
UIAppFonts =
{
“ChineseTakeaway.ttf”,
“Berylium.ttf”
},
UIApplicationExitsOnSuspend = false,
CFBundleURLTypes =
{
{
CFBundleURLSchemes =
{
“fb1234567890”,
}
}
}
},
},
}[/lua]

I changed the app id in the above and have quadruple checked that the one in my code is correct.
[import]uid: 60648 topic_id: 28437 reply_id: 114869[/import]

@thomas6 thanks but I have already tried that too: I was on 2012.774 so I moved to the latest stable 2012.840 and have just tried it on 2012.846.

Can anyone advise which build of Corona is working? [import]uid: 60648 topic_id: 28437 reply_id: 114870[/import]

It has worked with every build since it’s been released.

Do you have your bundle ID in your Provisioning Profile the same as the one in your FaceBook App settings?
[import]uid: 19626 topic_id: 28437 reply_id: 114873[/import]

@rob, @Danny thanks for all the feedback and sorry for being a muppet: there was a typo in the “iOS Bundle ID” setting on the facebook app settings page.
It’s weird and very confusing that it works without the facebook app installed even if your bundle is wrong.

For completeness I am using an ad hoc profile created from the same app as the “real” one. This allows you to have different testing versions for your various apps.

Hopefully this will help others. [import]uid: 60648 topic_id: 28437 reply_id: 114875[/import]

@rob,

OK!

You got me in! :slight_smile:

My next STEP will be to make a AdHoc profile for this app and see what FINALLY happens! :slight_smile:
I really appreciate your help.

PS: Sorry @james to have taken your forum as well.
Cheers guys,
Rodrigo. [import]uid: 89165 topic_id: 28437 reply_id: 114876[/import]

You have to be carefully too, if you copy from a table cell in a web browser. It sometimes will grab a space that you really cat see and you think you copied it right. That’s just general advice. I dunno if I’ve ever had that problem with coping the bundle ID. [import]uid: 19626 topic_id: 28437 reply_id: 114879[/import]

@rob ,

yes, thanks for the advice!

About this I keep my attention always and so am sure it isn`t my problem right now…but the “missing profile” that I will prepare for this app is the “problem” (I really think it is the “real culprit” because it was the “unique” thing I did not do at all) and so will see how it goes.
Lets see.

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 28437 reply_id: 114881[/import]

@rob,

I curiosity by my part:

How do you pass you app under Instruments? And what the AdHoc profile has to do with it?
Sorry for the dumb questions but I really do not know about that. :[

Thanks,
Rodrigo. [import]uid: 89165 topic_id: 28437 reply_id: 114893[/import]

@Rob!

My friend, THANK YOU VERY MUCH ! ! ! :slight_smile:

You were RIGHT!
and the RIGHT BIG QUESTION was:

•••Do you have your bundle ID in your Provisioning Profile the same as the one in your FaceBook App settings?•••

So after getting an AdHoc profile for my app (as I was using the Team Profile before) and building it, I still got nothing from Facebook connection and so I was going crazy again, but before become really crazy I came back here to this forum and read with attention your amazing question on the post above and Voilá , after SETTING the exactly same bundle ID of my AdHoc Profile INTO my Facebook App Settings/Dashboard (as I was using another one that makes reference to the other app am using the Apple ID there as well) all suddenly started to work as expected! WOW
So, my history with Facebook SSO integration is DONE right now! WOW again.

Its working and finally posting to the timeline. And for all other Devs having this same kind of problem, please, for your own sanity when integrating the "famous SSO" = Facebook Single-Sign-On, read all this forum carefully because I believe that it will help you guys/gals a LOT! ;) Thanks a bunch for **@RobMiracle** (isnt really a miracle? Hahaha).

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 28437 reply_id: 114998[/import]

i have same problem as james03
by testing corona’s facebook example on android with FB App installed
it always shows “loginFailed” at bottom after switch back from FB App to corona app
but without FB App installed (in another devices) its works fine. [import]uid: 133712 topic_id: 28437 reply_id: 117317[/import]

@corona199: as per my last comment the issue was because “there was a typo in the “iOS Bundle ID” setting on the facebook app settings page”.
My advice is to triple-check your settings. [import]uid: 60648 topic_id: 28437 reply_id: 118112[/import]