Trying to make the Facebook example project work!

I wish to add the facebook login on my game but I’m not able to make it working.

I’ve tried to start from the example that I found on the CoronaLabs package (SampleCode/Networking/Facebook/) but even that project doe not work… 

I’ve created a new app on Facebook I’ve enabled it for SSO.

I’ve substitute the  APP ID create to the build.settings and I’ve compiled the project, moved to my iPhone and tested.

On the console log I see:

Mar  7 17:25:07 iPhone-di-massimiliano kernel[0] <Debug>: launchd[972] Container: /private/var/mobile/Applications/BD2439C8-6E03-4F06-961F-BA9154653AB0 (sandbox)

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>: Facebook Listener events:

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>:    type(session)

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>:    name(fbconnect)

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>:    phase(loginFailed)

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>:    isError(true)

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>:    response(The operation couldn … #66)

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>: event.name    fbconnect

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>: event.type:    session

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>: isError: true

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>: didComplete: nil

Mar  7 17:25:07 iPhone-di-massimiliano Facebook[972] <Warning>: Session Status: loginFailed

Is there a way to understand why the login Fails?

I’ve also changed the appId on the main.lua file.

I’ve not set the apiKey because the comment say “Not needed at this time”

Hi @bertolini.max,

You should definitely read through both Facebook guides, since it’s crucial to understand some of the settings and processes about implementing it:

http://docs.coronalabs.com/guide/social/setupFacebook/index.html

http://docs.coronalabs.com/guide/social/implementFacebook/index.html

Hope this helps,

Brent

And this tutorial:  http://coronalabs.com/blog/2013/07/30/understanding-facebook-authentication/

Hi bertolini.max

What ended up being the solution to your problem. Ive read through all those guides numerous times and i still just cant get it to work, im obviously missing something, i just cant figure out what. It doesnt help that the guides are a little out of date when compared to the developer facebook options you actually get presented with. 

Im also seeing “com.facebook.sdk error 2” in the console and also “app not setup the developers of this app have not set up this app properly for facebook login” when trying different things to make it work. I had no issues with my previous fb implementation, but that was about 15 months ago, just cant make it work with the new api. 

Cheers

Can you post a screen shot of your screen from developers.facebook.com?

Hi Rob,

I have taken the facebook sample app provided by corona as a basis to try and get integration working with no luck. Here is the details of what i have done.

  1. Create a provisioning profile specifically for this test app. In this case net.pocketplayground.coronasampleapp

  2. Create a new app in facebook developer portal

  3. Add an “iOS” platform to the app in fb dev portal.Set the bundle ID to net.pocketplayground.coronasampleapp to match my provisioning profile. Specify the store id of an existing app (i just referenced one of my other apps that i have published). Enable SSO. Enable Deep Linking.

  4. Left the other settings as default on the advanced and migrations page. (note: i wasnt sure about the “Native or Desktop app” setting, so i tried it both ways. 

Advanced page with Native or Desktop disabled

Advanced page with Native or Desktop enabled

Migrations page

  1. Set the required app id fields in the sample app

In build settings

            FacebookAppID = “645295625542769”,    – replace XXXXXXXXX with your facebook appId

            CFBundleURLTypes =

            {

                {

                    CFBundleURLSchemes =

                    {

                        “fb645295625542769”,    – replace XXXXXXXXX with your facebook appId

                    }

                }

            }

in main.lua

local appId  = “645295625542769”    – Add  your App ID here (also go into build.settings and replace XXXXXXXXX with your appId under CFBundleURLSchemes)

local apiKey = nil    – Not needed at this time

  1. Compile the app using my coronasampleapp provisioning profile

  2. Test the app using my iPad3 (iOS 5.1.1) which does not have the facebook app installed

Then when i click ok to return to the corona app, that just fails with this error (note the address bar)

  1. Test the app using my iPhone5 (iOS 6.0.2) which does have the facebook app installed

Same error, however pressing ok returns to the corona sample app correctly.

Note i am using the latest public release of Corona 2014.2189 (installed the (2189a) build on the mac).  

So thats everything i did (based on the instructions in the links you provided). I have also attached the facebook sample app with the changes i made to the app id’s for your reference. 

On a related note, a couple of doco and sample issues i noted.

A note re the instructions at http://docs.coronalabs.com/guide/social/setupFacebook/index.html. It says " iPhone App Store ID  and/or  iPad App Store ID  is required for Facebook  Single Sign-On. See the Build Settings (iOS) section below for further details", that Build Settings iOS link goes nowhere and there is no “Build Settings (iOS)” section below. 

Another note re the facebook sample app that comes with corona, in main.lia where you get people to specify their app id 

local appId  = XXXXXXXXX     – Add  your App ID here (also go into build.settings and replace XXXXXXXXX with your appId under CFBundleURLSchemes)

It should really be local appId = “XXXXXXXXX”  <-- note the quotes, as the facebook.login function requires a string, not a number. The original line indicates that it is a number, as you tell people to just replace the XXXXXXXX part with their id. 

Please advise as I am complete stuck at the moment. 

Cheers

Craig

In step 6 you marked out some information.  You need to use a provisioning profile that uses a Bundle ID that matches what you told Facebook you are using.  That is likely the issue.

Rob

Thats my developer ID that i blacked out. So your saying i need to put the developer id in front of the app id? eg XXXXXXX.net.pocketplayground.coronasampleapp? I did try that previously but i will give it another go with this sample app. 

I guess I mis-read that. It didn’t look like the profile you had selected in corona was the same as the one you created in the provisioning portal.  Looking at one of my apps that I know works, you should turn on a couple of things that are off:

Native or Desktop.app should be on.

Embedded browser oAuth Login should be on.

Try those…

Rob

I have turned those two settings on but its still reporting the same error.

Note: I have only tried on my iPhone5 so far which has the facebook application installed, i will try the iPad with the web sign in later once i get home. 

Have now tried the iPad with the web sign in and same error still with that.

Can you post the console.log from your device?

Thanks

Rob

Hi Rob,

Attached is the console app results from attempting to run the app and login to fb. 

Regards

Craig

I’ve also changed the appId on the main.lua file.

I’ve not set the apiKey because the comment say “Not needed at this time”

This may be of some use helping diagnose this:

http://stackoverflow.com/questions/14159965/com-facebook-sdk-error-2-on-ios

Hi @bertolini.max,

You should definitely read through both Facebook guides, since it’s crucial to understand some of the settings and processes about implementing it:

http://docs.coronalabs.com/guide/social/setupFacebook/index.html

http://docs.coronalabs.com/guide/social/implementFacebook/index.html

Hope this helps,

Brent

And this tutorial:  http://coronalabs.com/blog/2013/07/30/understanding-facebook-authentication/

Yeah i have already read that post when originally trying to diagnose the issue. To address their points, 

  • BundleIdentifier and BundleURLName - have confirmed these match
  • The app is still in Sandbox mode - not sure what this refers to exactly, i presume its something from the old facebook developer portal UI. Perhaps it corrosponds to the “Status and Review” page setting about makign it available to the public whcih i currently have set to no, as its not a released app yet.
  • The app does not appear at all in the Facebook Settings (device’s settings -> Facebook -> Allow These Apps To Use Your Account), i dont have this section at all in fact. I would imagine this would only reply to devices with the facebook app installed, however problems occurs with both the fb app and web login.
  • Apparently phonegap had some permissions error that they had to fix, assuming corona doesnt have this problem.

Have you tried actually compiling and running the sample app i attached? Could you create a new App in the FB dev portal and setup the sample app i provided to use it and see if you get the same problem as i do or not?

Thanks

The sample you sent looks like the standard FB app with your AppID.  Is there anything different?