question

prasanth.akon@gmail.com avatar image
prasanth.akon@gmail.com asked

Getting Facebook ID from Playfab ID

Hello,

My name is Prasanth. I'm using Playfab plugin for managing leaderboards(both global and facebook). I'm using Loginwithfacebook function to login my players via facebook. The problem now is i want profile picture of my friends in facebook leaderboards. So what I'm doing is i'm getting list of playfab id from GetFriendLeaderboardAroundCurrentUser() method and storing it in a list.

So inorder to get facebook id from playfab id i'm using the following method:

//Current ID number is incrementing value where it increments when the first id has been successfully retrieved. 

GetAccountInfo(PlayFabID[CurrentIdNumber]);    //PlayFabID[] is a list

void GetAccountInfo(string playfabID)
{
   Debug.Log("PlayFabID " + playfabID);
   GetAccountInfoRequest userinforequest = new GetAccountInfoRequest()
   {
     PlayFabId = playfabID
   };
   PlayFabClientAPI.GetAccountInfo(userinforequest, accountinforesult,    OnApiCallError);
}
void accountinforesult(GetAccountInfoResult result)
{
    Debug.Log("facebookID" + result.AccountInfo.FacebookInfo.FacebookId);
    FacebookString = result.AccountInfo.FacebookInfo.FacebookId;
    FacebookID.Add(FacebookString);
    FB.API("/" + FacebookString + "/picture", HttpMethod.GET,    ApplyProfilePicture);
}

Note that i'm using FacebookString as retrieved facebook id into FB.API to get the facebook profile picture.

The error i'm getting is:

HTTP:200
ERROR:Unknown -- System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
at FacebookLeaderboard.accountinforesult

 

Any suggestions on how to fix this error and retrieve the profile picture with ease. And what is the best way to retrieve multiple account picture of the users(maximum 10)?

Thank You.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Unfortunately, querying for info from all of a player's friends at once could be problematic. I understand that you're limiting this to 10 at a time, but the issue is that if a player quickly tabs through the leaderboard, this could mean potentially hundreds of calls in short order, which would be outside the bounds of our fair use policy (in our terms of service). You should also bear in mind Facebook's limits: https://developers.facebook.com/docs/graph-api/advanced/rate-limiting. In short, a subset of your users could potentially eat up your call allowance with Facebook quite quickly.

What I would recommend instead is that you only query for the individual user's Facebook info when the player clicks on that friend's name, taking them to a "view this player" type of view. You could potentially also query for just the top player's image (or possibly top 3 or so) on the leaderboard, but then not display images for anyone below that as they page through the leaderboard.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

prasanth.akon@gmail.com avatar image
prasanth.akon@gmail.com answered

Exactly. That's why i'm using CurrentIdNumber to fetch only one id at a time. The CurrentIdNumber increments after each successful picture retrieval.Thinking of keeping loading screen in this process. The error i'm getting is with the GetAccountInfo(), that it works for only for some playfab id to retrieve their facebook id. But according to players tab in my dashboard all of them has facebook id included in their account. Any ideas or trick to get this work?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Can you give us the specifics of a PlayFab ID this isn't working for? When you make the call to get the account info, everything should be returned, including any Facebook ID the player has.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

prasanth.akon@gmail.com avatar image
prasanth.akon@gmail.com answered

I couldn't find any specific reason why it's not working. As far as i know, every playfab Id has facebook id in their facebook linked account in dashboard. 

This is the error i'm getting:

HTTP:200
ERROR:Unknown -- System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
at FacebookLeaderboard.accountinforesult (PlayFab.ClientModels.GetAccountInfoResult result) [0x00000] in D:\unityProjects\Badminton Game\Badminton3D\badminton3d\Assets\Scripts\FacebookLeaderboard.cs:224
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d0] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000eb] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000b9] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:443
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00018] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/MulticastDelegate.cs:71
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:415
at PlayFab.Internal.ResultContainer`1[PlayFab.ClientModels.GetAccountInfoResult].HandleResults (PlayFab.CallRequestContainer callRequest, System.Delegate resultCallback, PlayFab.ErrorCallback errorCallback, System.Action`2 resultAction) [0x00093] in D:\unityProjects\Badminton Game\Badminton3D\badminton3d\Assets\PlayFabSDK\Internal\ResultContainer.cs:53

UnityEngine.Debug:LogError(Object)
FacebookLeaderboard:OnApiCallError(PlayFabError) (at Assets/Scripts/FacebookLeaderboard.cs:137)
PlayFab.Internal.ResultContainer`1:HandleResults(CallRequestContainer, Delegate, ErrorCallback, Action`2) (at Assets/PlayFabSDK/Internal/ResultContainer.cs:84)
PlayFab.<GetAccountInfo>c__AnonStorey22:<>m__1C(CallRequestContainer) (at Assets/PlayFabSDK/Public/PlayFabClientAPI.cs:526)
PlayFab.CallRequestContainer:InvokeCallback() (at Assets/Plugins/PlayFabShared/PlayFabErrors.cs:263)
PlayFab.Internal.<MakeRequestViaUnity>c__Iterator6:MoveNext() (at Assets/PlayFabSDK/Internal/PlayFabHTTP.cs:260)

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Based on the error, it looks like the account in question does not actually have a Facebook ID - that's why I'd like to look at a specific user account that reproduces this problem. Another thing you could do would be to put a breakpoint in the code in order to check the data in the response, and verify whether it has one.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Michal Töpfer avatar image
Michal Töpfer answered

I am probably getting similar error. I have two test users generated from Facebook and then linked to PlayFab (they are FB friends). When I log in as one of the users and try to GetAccountInfo of the other one, I don't recieve the Facebook ID. 

Postman Response (GetAccountInfo(PlayFabId = 5DEA1422AE16888A); signed in as FC7D6D6F7551D049:

{
"code": 200,
"status": "OK",

"data": {
"AccountInfo": {
"PlayFabId": "5DEA1422AE16888A",
"Created": "0001-01-01T00:00:00Z",
"TitleInfo": {
"DisplayName": "Dave Alabjhfajehhc Shepar",
"Created": "0001-01-01T00:00:00Z"
}
}
}
}

User has FB ID.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Ah, I see - you're querying for another user's info. In that case, you'll want to use the GetFriendsList call to get the info you need on account IDs. The issue here is that by policy, the ID shouldn't be given to anyone who isn't a friend, so the GetAccountInfo call doesn't return it. However, you do get it for all your friends via GetFriendsList.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

marcos avatar image marcos commented ·

How can I get the UserFacebookInfo of people who is not a friend of the player? Otherwise, if using LoginWithFacebook, then the general leaderboard would not have any info other than position and score for people who are not friends. I could do it anyway by storing manually the fb id of each person, as well as its name, so not sure Im understanding the limitations correctly. Would you elaborate a bit? (Thanks!)

0 Likes 0 ·
brendan avatar image brendan marcos commented ·

The issue is that we do have to comply with Facebook's policies, and that does not allow for providing information on Facebook accounts in apps to non-friends.

1 Like 1 ·
prasanth.akon@gmail.com avatar image
prasanth.akon@gmail.com answered

Does  GetFriendsList() returns the facebook id by the rank in leaderboard? Because i want to show the profile picture by their rank. Right now it returns alphabetically i guess?

Thank you.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Because we're aggregating multiple friends systems, I can't guarantee that the friends will always be returned in alphabetical order, but I can confirm that they are not returned in leaderboard order. So yes, you do need to iterate on the friends list to find the Facebook ID for your friends.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.