question

zrdeland avatar image
zrdeland asked

Client GetFriendsListRequest will not allow me to show or return statistics

The following code returns Object reference not set to an instance of an object at the line with the comment.

PlayFab.ClientModels.GetFriendsListRequest request = new PlayFab.ClientModels.GetFriendsListRequest();

request.IncludeFacebookFriends = true;
request.IncludeSteamFriends = false;
request.ProfileConstraints.ShowStatistics = true; //null reference occurs here

PlayFabClientAPI.GetFriendsList(request, result => {
   DisplayFriends(result.Friends);
}, error => Debug.LogError(error.GenerateErrorReport()));

If I exclude the line "request.ProfileConstraints.ShowStatistics = true;" the code runs without the error, however, no statistics are returned within Profile.

I have enabled Statistics in ALLOW CLIENT ACCESS TO PROFILE PROPERTIES:

apisFriends
10 |1200

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

Brian Jordan avatar image
Brian Jordan answered

You'll want to initialize a Profile Constraints object, changing line 5 like so:

request.ProfileConstraints = new PlayerProfileViewConstraints() {ShowStatistics = true};

(The {}s after the constructor allow you to set field values on the new object inline, you could alternatively put it in a variable and initialize it separately.)

10 |1200

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

zrdeland avatar image
zrdeland answered

Thanks Brian, that solved the initial problem but created another. I now get a null reference for FacebookInfo.facebookId. It was working before your solution above.

details.FacebookID = f.FacebookInfo.FacebookId; // object reference is null
private void GetFriends()
    {
        PlayFab.ClientModels.GetFriendsListRequest request = new PlayFab.ClientModels.GetFriendsListRequest();
        request.IncludeFacebookFriends = true;
        request.IncludeSteamFriends = false;
        request.ProfileConstraints = new PlayerProfileViewConstraints() { ShowStatistics = true };
        PlayFabClientAPI.GetFriendsList(request, result => {
            DisplayFriends(result.Friends);
        }, error => Debug.LogError(error.GenerateErrorReport()));
    }


    private void DisplayFriends(List<PlayFab.ClientModels.FriendInfo> friends)
    {
        friends.ForEach(f => {
        Debug.Log(f.FriendPlayFabId);
        GameObject friend = Instantiate(FriendItemPrefab, FriendsListParent.transform) as GameObject;
        //Image ProfilePic = null;


        if (FriendsListParent != null)
        {
            //friend.transform.SetParent(FriendsListParent.transform, false);
            if (friend != null)
            {
                //Store friend values                    
                FriendDetails details = friend.GetComponent<FriendDetails>();
                details.PlayFabID = f.FriendPlayFabId;
                details.FacebookID = f.FacebookInfo.FacebookId; //NULL REFERENCE HERE
                details.DisplayName = f.TitleDisplayName;
                //grab the level and xp stats 
                Debug.Log("Statisitcs length = "+ f.Profile.Statistics.Count);
                
                foreach (var stat in f.Profile.Statistics)
                {
                        if (stat.Name == "level")
                            details.Level = stat.Value.ToString();


                        if (stat.Name == "xp")
                            details.XP = stat.Value.ToString();
                }
                


                //for now, query Facebook to retreive image
                FetchFirendsProfileImage(details.FacebookID, friend);


                //display the level and xp stats if not null
                if (!string.IsNullOrEmpty(details.Level))
                    friend.transform.Find("RankBase/Rank").gameObject.GetComponent<Text>().text = details.Level;
                
                //Add onClick Listener to the invite button
                friend.transform.Find("Invite").gameObject.GetComponent<Button>().onClick.AddListener(() => friendlyMatchCtlr.ChallengeFriend(friend.transform.Find("Invite").gameObject.GetComponent<Button>(), details));
                DisableButton(friend.transform.Find("Invite").gameObject.GetComponent<Button>());


                //Add onClick Listener to the chat button
                friend.transform.Find("Chat").gameObject.GetComponent<Button>().onClick.AddListener(() => chatManager.ShowPMPopup(friend.transform.Find("Chat").gameObject.GetComponent<Button>(), details));
            }
            else Debug.Log("The friend gameobject is null");
        }


        });// end foreach


    }
8 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.

brendan avatar image brendan commented ·

This is a known issue currently. Please see this thread for more info on this: https://community.playfab.com/questions/16803/unity-getfriendslist-facebook-and-profile-info-in.html.

0 Likes 0 ·
zrdeland avatar image zrdeland commented ·

As a temporary work around I implemented a friendleaderboardaroundplayer however it does not provide access to the friends facebook ids in the results.

I only need to know it once a button is clicked for a specific friend. Is there an API call to load a friend's profile info with the Facebook ID?

0 Likes 0 ·
zrdeland avatar image zrdeland zrdeland commented ·

I have tried using a second call to GetFriendsList WITHOUT profile view constraints when a button for a specific friend is clicked...the GetFriendsList is returning null values for FacebookInfo.FacebookId....

//retrieve facebookId from GetFriendsList
                PlayFab.ClientModels.GetFriendsListRequest request = new PlayFab.ClientModels.GetFriendsListRequest();
                request.IncludeSteamFriends = false;
                PlayFabClientAPI.GetFriendsList(request, result => {
                    result.Friends.ForEach(f=> {
                        if (f.FriendPlayFabId == details.PlayFabID)
                        {
                            details.FacebookID = f.FacebookInfo.FacebookId; //NULL HERE
                            Debug.Log("Successfully retrieved facebook ID: " + f.FacebookInfo.FacebookId); //NULL HERE
                        }
                        else
                            Debug.Log(f.FriendPlayFabId+" != "+details.PlayFabID);
                    });//end foreach
                    
                }, error => Debug.LogError(error.GenerateErrorReport()));

0 Likes 0 ·
brendan avatar image brendan zrdeland commented ·

What are the Title ID and the PlayFab IDs that you're using for the test, so that we can have a look?

0 Likes 0 ·
Show more comments
zrdeland avatar image zrdeland commented ·

I think you're correct Brendan. The test user is not an actual FB friend of my developer account on Facebook.I tested again with 2 test users that are Facebook friends and it appears to work. Thanks!

Is there any ETA for resolving the profile contraints bug? returning the FacebookInfo with constraints will eliminate many additional API calls within our app.

0 Likes 0 ·
brendan avatar image brendan zrdeland commented ·

We'll be posting on the other thread, where we're tracking on that issue, as soon as we have an update.

0 Likes 0 ·

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.