Does not retrieve friend nor correct user_id from Facebook

Hi,

I’m doing a login with Facebook and my name popup, I accept etc. and everything seems to work smoothly.

I save the user_id into a Global variables as I use it as a unique identifier:

local response = json.decode( event.response ) local myID = util.FBConvert( response.id )

The problem starts here, myID is not myID. It’s something called app_scoped_id.

Anywho, it doesn’t complain so I would like to show a facebook dialog with all my friends but the list is empty. The same happens if I request them instead, it just returns an empty list.

I think this has todo with Facebook changing their API but I’m not sure.

I changed the FB settings according to this post:

http://forums.coronalabs.com/topic/47833-facebook-v2-on-ios-wrong-login-window-is-shown/

I also tried what “schroederapps” posted but with no luck.

Any help with this is highly appreciated.

Best regards,

Tomas

The complete code:

local function requestFriends( event ) print("DEBUG: facebookListenerLogin") print("event.type: " .. tostring(event.type)) print("event.phase: " .. tostring(event.phase)) if ( "session" == event.type ) then if ( "login" == event.phase ) then facebook.request( "me/friends" ) --, "GET", params ) end elseif ( "request" == event.type ) then if ( not event.isError ) then local response = json.decode( event.response ) for k, v in pairs(response) do print(k,v) end print(" \*\*\* START FRIENDS \*\*\* ") for key,value in pairs(response.data) do print(key,value) end end end end local function facebookListener( event ) if ( "session" == event.type ) then if ( "login" == event.phase ) then timer.performWithDelay(500, function() facebook.request( "v2.0/me" ) --, "GET", params ) facebook.login( fbAppID, requestFriends, { "public\_profile", "user\_friends"} ) end) end elseif ( "request" == event.type ) then if ( not event.isError ) then local response = json.decode( event.response ) \_G.PlayerID = util.FBConvert( response.id ) if \_G.PlayerID ~= nil then local function onComplete() end facebook.showDialog("friends", onComplete) --storyboard.gotoScene("scene\_main") else local txt = display.newText( "Could not login to Facebook!", 50, 50, native.systemFont, 16) end end end end function M.login() facebook.login( fbAppID, facebookListener ) --{ "public\_profile", "user\_friends" }) end

I have modified it several time but this is the latest code.

What is the value of event.response before you json.decode it?

Hi Rob,

As I expected this had something to do with the new API 2.0 version.

Right now I will not receive back my user_id but my app_scoped_id so there is nothing to be scared about, but it will be harder to use two different apps when you want to share a highscore between them or something like that.

I can also inform that requesting friends is a little bit different:

facebook.request( "me/friends", "GET", { fields = "id,first\_name,last\_name,picture" } ) facebook.request( "me/invitable\_friends" ) 

The first one, “me/friends”, will get all the friends that have the app installed, not like before when you receieved all your friends with a installed flag. “me/invitable_friends” will return the remaining friends i.e. the ones that does not have it installed however this requires that you make some changes in the Facebook Developer console:

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/invitable_friends

Best regards,

Tomas

The complete code:

local function requestFriends( event ) print("DEBUG: facebookListenerLogin") print("event.type: " .. tostring(event.type)) print("event.phase: " .. tostring(event.phase)) if ( "session" == event.type ) then if ( "login" == event.phase ) then facebook.request( "me/friends" ) --, "GET", params ) end elseif ( "request" == event.type ) then if ( not event.isError ) then local response = json.decode( event.response ) for k, v in pairs(response) do print(k,v) end print(" \*\*\* START FRIENDS \*\*\* ") for key,value in pairs(response.data) do print(key,value) end end end end local function facebookListener( event ) if ( "session" == event.type ) then if ( "login" == event.phase ) then timer.performWithDelay(500, function() facebook.request( "v2.0/me" ) --, "GET", params ) facebook.login( fbAppID, requestFriends, { "public\_profile", "user\_friends"} ) end) end elseif ( "request" == event.type ) then if ( not event.isError ) then local response = json.decode( event.response ) \_G.PlayerID = util.FBConvert( response.id ) if \_G.PlayerID ~= nil then local function onComplete() end facebook.showDialog("friends", onComplete) --storyboard.gotoScene("scene\_main") else local txt = display.newText( "Could not login to Facebook!", 50, 50, native.systemFont, 16) end end end end function M.login() facebook.login( fbAppID, facebookListener ) --{ "public\_profile", "user\_friends" }) end

I have modified it several time but this is the latest code.

What is the value of event.response before you json.decode it?

Hi Rob,

As I expected this had something to do with the new API 2.0 version.

Right now I will not receive back my user_id but my app_scoped_id so there is nothing to be scared about, but it will be harder to use two different apps when you want to share a highscore between them or something like that.

I can also inform that requesting friends is a little bit different:

facebook.request( "me/friends", "GET", { fields = "id,first\_name,last\_name,picture" } ) facebook.request( "me/invitable\_friends" ) 

The first one, “me/friends”, will get all the friends that have the app installed, not like before when you receieved all your friends with a installed flag. “me/invitable_friends” will return the remaining friends i.e. the ones that does not have it installed however this requires that you make some changes in the Facebook Developer console:

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/invitable_friends

Best regards,

Tomas