Facebook Request Friends and Email

Great - thanks Rob!  I’ll give it a go

Update: I thought it was working… but turns out I was wrong.

@Rob, please could you paste your exact code here?

@Renato, did you ever get this working?

For your info, here’s the code I’m using:

[lua]

local fbAppID = <myFacebookAppID>

local function facebookListener( event )

    if event.type == “session” then

      if event.phase == “login” then

        local fbSessionToken = event.token

        local fbSessionExpiry = event.expiration

        if fbSessionToken then

         local params = {

              fields = “first_name,last_name,email”

           }

           facebook.request( “me”, “GET”, params )

        end

      end

    elseif event.type == “request” then

      if not event.isError then

        print("response is " … event.response)

        local response = json.decode( event.response )

      else

        native.showAlert( “Ooops!”, “There was a problem connecting to Facebook.  Check your Internet connection and try again…”, { “Ok” } )

        native.setActivityIndicator(false)

      end

    end

end

facebook.login( fbAppID, facebookListener,{ “email” } )

[/lua]

Here’s how I reproduce the problem:

  1. Delete the Facebook app from my personal Facebook settings (ie I’m now effectively a first time user)

  2. Delete the iOS app from my phone

  3. Install the iOS app onto my phone

  4. Open the iOS app and run the code above

The problem:

  • when navigating to the Facebook iOS app, I’m told “<app name> will receive the following info: your public profile.”… note, it doesn’t ask for email permission

  • email address is not returned in event.response (first name, last name, and id are returned ok)

(- I am able to get the email request by running 2 separate facebook.login calls - but this has the problem of showing a Facebook webview when the user is returned to my iOS app from the Facebook app)

I’m running iOS 7 and Corona version 2014.2189.

P.S. @Rob, please could you confirm that your solution worked even after deleting the Facebook app from your personal Facebook settings… if it’s the second time my user is logging in, my code works as expected also.  Thanks.

I got it working requesting the e-mail permission after I receive the public permissions. So, first I request the public permissions and on its listener I request the e-mail permission.

You need to do two logins.  The first one gets the basic permissions, the second one asks for additional permissions.  This is how Facebook wants it.

The facebook sample app does exactly this process.  What the sample app doesn’t do is ask for the email permission or request email as a field to be returned on the “me” call.  I’ve updated my Corona SDK since I posted this so my changes were overwritten with the latest daily build, but looking at SampleCode/Networking/Facebook/main.lua here are the changes that I made:

In main.lua line 189, change:

        facebook.request( “me” )

to:

            local params = {
                fields = “name,username,first_name,last_name,picture,installed,email”
            }
            facebook.request( “me”, “GET”, params )

Then change line 289 from:

        facebook.login( appId, listener, {“publish_actions”}  )

to

        facebook.login( appId, listener, {“publish_actions”,“email”}  )

And give that a go.

Rob

@Rob, thanks for the reply.  Unfortunately I’m still getting a problem with the Facebook sample app.  I changed the lines of code as you suggested (and also changed the Facebook appId in build.settings and main.lua), but I get the following error printed to the console of my device:

The ‘Passive’ connection ‘Facebook’ access to protected services is denied.

(Then after 20 seconds, a Facebook web view is displayed and I’m navigated to the Safari iOS app - which is the same problem I had before when using two Facebook login calls)

However, the second time I open the Sample Facebook iOS app, I have no such problem.  I’d be really grateful if you could confirm whether or not you’re getting this problem, or if you have an idea of what’s going wrong (I’m stumped!)

Thanks,

Ed

@Renato, thanks - although I still have a (different) problem when making two Facebook logins (as mentioned above)

The slow login using the web browser is a problem that’s been reported to the engineers.  But once you get logged in (and it will log you in), things work like they should.

Rob

Ok, thanks Rob… although if it were just a bit slow, I could deal with that.  At the moment, it’s barely useable.  Surely this isn’t what every Corona app using Facebook looks like at the moment?

Video of Facebook Sample App:

http://youtu.be/U9kbBvr7QT8

  1. 20 second delay

  2. Doesn’t open the native Facebook app (it opens Safari)

  3. When navigating back to the Facebook Sample App, the user has to close (or log in a second time through) a Facebook web view

Hi @edmoyse, like I said the engineers are aware of it.  No, this isn’t a good situation, but it also doesn’t seem to be effecting everyone either. 

Also regarding your video link:  It’s on site with ads for porn services and it never played the video and started a series of popup’s.  Please try to avoid using sites that are going to potentially take people to sites with inappropriate content.

As I said above, once you get through that painful initial login, it seems to behave as expected as long as you stay logged in (requesting additional permissions, etc.)

Rob

Well I didn’t originally want to upload it to my YouTube account… and that video sharing service clearly has very good SEO :wink:

Anyway, edited it now - hopefully you can view it.

What’s the expected time frame for the fix, and will it be released as a daily build?

Thanks again,

Ed

P.S. you said it doesn’t seem to be affecting everyone… do you know who it isn’t affecting, and is there a way I can become part of the unaffected?

@edmoyse, if I knew how to get you unaffected, I wouldn’t need engineering to look at this :-)  I don’t know specific people, but there are more than the 4 people reporting this using Facebook, ergo, it doesn’t seem to be affecting everyone.

Rob

Ok - thanks Rob.  Do you have any idea how long it’ll be?  I don’t want to release with this problem…

Unfortunately, no I don’t. 

Do you know whether this is a low or high priority task for the engineers to look into?  

At the moment I’m completely in the dark - so don’t know whether to wait or try something else… I have no idea what fraction of users this problem is affecting - e.g. if I’m among 1%, then I could be waiting a very long time.

Can you try building again?

We made an update to the plugin today and I’m no longer experiencing this issue.

Rob

You could use a 3rd party service like Scoreoid and register usernames there.

It is a way to circumvent the need to publish things on FB (like publish to friends) and still be able to connect to friends (from FB user_friends list).

I haven’t tested if this affects the number of logins.

@Rob, brilliant - tested it, and so far it seems to be working - thanks!

Update: I thought it was working… but turns out I was wrong.

@Rob, please could you paste your exact code here?

@Renato, did you ever get this working?

For your info, here’s the code I’m using:

[lua]

local fbAppID = <myFacebookAppID>

local function facebookListener( event )

    if event.type == “session” then

      if event.phase == “login” then

        local fbSessionToken = event.token

        local fbSessionExpiry = event.expiration

        if fbSessionToken then

         local params = {

              fields = “first_name,last_name,email”

           }

           facebook.request( “me”, “GET”, params )

        end

      end

    elseif event.type == “request” then

      if not event.isError then

        print("response is " … event.response)

        local response = json.decode( event.response )

      else

        native.showAlert( “Ooops!”, “There was a problem connecting to Facebook.  Check your Internet connection and try again…”, { “Ok” } )

        native.setActivityIndicator(false)

      end

    end

end

facebook.login( fbAppID, facebookListener,{ “email” } )

[/lua]

Here’s how I reproduce the problem:

  1. Delete the Facebook app from my personal Facebook settings (ie I’m now effectively a first time user)

  2. Delete the iOS app from my phone

  3. Install the iOS app onto my phone

  4. Open the iOS app and run the code above

The problem:

  • when navigating to the Facebook iOS app, I’m told “<app name> will receive the following info: your public profile.”… note, it doesn’t ask for email permission

  • email address is not returned in event.response (first name, last name, and id are returned ok)

(- I am able to get the email request by running 2 separate facebook.login calls - but this has the problem of showing a Facebook webview when the user is returned to my iOS app from the Facebook app)

I’m running iOS 7 and Corona version 2014.2189.

P.S. @Rob, please could you confirm that your solution worked even after deleting the Facebook app from your personal Facebook settings… if it’s the second time my user is logging in, my code works as expected also.  Thanks.

I got it working requesting the e-mail permission after I receive the public permissions. So, first I request the public permissions and on its listener I request the e-mail permission.

You need to do two logins.  The first one gets the basic permissions, the second one asks for additional permissions.  This is how Facebook wants it.

The facebook sample app does exactly this process.  What the sample app doesn’t do is ask for the email permission or request email as a field to be returned on the “me” call.  I’ve updated my Corona SDK since I posted this so my changes were overwritten with the latest daily build, but looking at SampleCode/Networking/Facebook/main.lua here are the changes that I made:

In main.lua line 189, change:

        facebook.request( “me” )

to:

            local params = {
                fields = “name,username,first_name,last_name,picture,installed,email”
            }
            facebook.request( “me”, “GET”, params )

Then change line 289 from:

        facebook.login( appId, listener, {“publish_actions”}  )

to

        facebook.login( appId, listener, {“publish_actions”,“email”}  )

And give that a go.

Rob