Facebook v4 API

Hi, I’m a newbie in Corona and I would like my app to connect to facebook and get the email address or what’s unique in that account that I can get. 

The facebook.request( “me” ) only allows me to access facebook profile name, which is not unique because different facebook accounts can have the same profile names. Is there any possible way that I can get facebook email? Thanks

There are two things you need to do.

  1. Ask permission to access the email address.

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

  2. Request it as part of the “me” request.

    facebook.request( “me”, “GET”, { fields =“email” } )

or something like that.

Rob

Hi Rob,

I got confused. I tried using this code, I couldn’t figure out what’s wrong.

local function listener(event) if ("session" == event.type) then local response = facebook.request( "me", "GET", { fields ="email" } ) printTable(response) elseif ("request" == event.type) then local response = event.response if (not event.isError) then local data = json.decode(response) statusMessage.data.text = data.email end end end facebook.login( listener, {"publish\_actions", "email"} )

Can you give a sample that would allow me to print the email I have just retrieved? Big thanks!

Yla

local function listener(event) if ("session" == event.type) then local response = facebook.request( "me", "GET", { fields ="email" } ) printTable(response) elseif ("request" == event.type) then printTable(response) --\<-------- added this line local response = event.response if (not event.isError) then local data = json.decode(response) statusMessage.data.text = data.email end end end facebook.login( listener, {"publish\_actions", "email"} )

Add the printTable like I did above and then post the results you get in your console log.

Rob

Hi Rob,

printTable is only printable in console. I won’t be able to test this because ‘plugin.facebook.v4’ is not available in corona simulator. I’m trying to display the response as statusMessage.data.text but the data.email is not working.

Yla

I found the solution in this thread:

https://forums.coronalabs.com/topic/63695-i-am-not-able-to-get-user-profile/

Thanks Anyway!

You can get the device console.  Please read: http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob

There are two things you need to do.

  1. Ask permission to access the email address.

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

  2. Request it as part of the “me” request.

    facebook.request( “me”, “GET”, { fields =“email” } )

or something like that.

Rob

Hi Rob,

I got confused. I tried using this code, I couldn’t figure out what’s wrong.

local function listener(event) if ("session" == event.type) then local response = facebook.request( "me", "GET", { fields ="email" } ) printTable(response) elseif ("request" == event.type) then local response = event.response if (not event.isError) then local data = json.decode(response) statusMessage.data.text = data.email end end end facebook.login( listener, {"publish\_actions", "email"} )

Can you give a sample that would allow me to print the email I have just retrieved? Big thanks!

Yla

local function listener(event) if ("session" == event.type) then local response = facebook.request( "me", "GET", { fields ="email" } ) printTable(response) elseif ("request" == event.type) then printTable(response) --\<-------- added this line local response = event.response if (not event.isError) then local data = json.decode(response) statusMessage.data.text = data.email end end end facebook.login( listener, {"publish\_actions", "email"} )

Add the printTable like I did above and then post the results you get in your console log.

Rob

Hi Rob,

printTable is only printable in console. I won’t be able to test this because ‘plugin.facebook.v4’ is not available in corona simulator. I’m trying to display the response as statusMessage.data.text but the data.email is not working.

Yla

I found the solution in this thread:

https://forums.coronalabs.com/topic/63695-i-am-not-able-to-get-user-profile/

Thanks Anyway!

You can get the device console.  Please read: http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob