Transporting PlayFab friends to Photon

Can anyone guide me how can I transport my friendslist from PlayFab to Photon? I have got authentication successfully done as it is given in the docs. I am using Photon Unity Networking. Is it necessary to join a room before getting friends list or friends list can be retrieved if only connected to master server also?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited July 2018
    Hi @avimon,

    Why do you need to move your PlayFab's friends list from PlayFab to Photon?
    Photon's FindFriends feature works outside of rooms, it informs you if users are connected or not and if connected if they are in a room or not and if they are in a room which one.
  • @JohnTube I want to get online status of player and invite them for matchmaking
  • JohnTube
    JohnTube ✭✭✭✭✭
    1- get the list of friends from PlayFab using one of their client API methods
    2- get the PlayFabIds from that list into a string array (string[])
    3- call PhotonNetwork.FindFriends using the at array of UserIDs from 2
    4- wait for the callback void OnUpdatedFriendList()
  • @JohnTube
    I am using this code :
    private void OnConnectedToMaster() {
            GetFriends();
        }
    
    public void GetFriends() {
            PlayFabClientAPI.GetFriendsList(
                new GetFriendsListRequest() { ProfileConstraints = null },
                FriendListResult,
                OnPlayFabError);
        }
    
    private void FriendListResult(GetFriendsListResult result) {
            for (int i = transform.childCount - 1; i >= 0; i--) {
                Destroy(transform.GetChild(i).gameObject);
            }
    
            string[] friendsToFind = null;
            FriendInfo = result.Friends;
    
            for (int i = 0; i < result.Friends.Count; i++) {
                PlayFab.ClientModels.FriendInfo friendInfo = result.Friends.ElementAt(i);
                friendsToFind[i] = friendInfo.FriendPlayFabId;
            }
            PhotonNetwork.FindFriends(friendsToFind); 
        }
    
        private void OnUpdatedFriendList() {
            Debug.Log(PhotonNetwork.Friends.Count);
        }
    but I am getting errors. What am I doing wrong?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited July 2018
    What errors? Can you share the error message and stacktrace?

    You need to create the array first:

    instead of:
    string[] friendsToFind = null;
    do:
    string[] friendsToFind = new string[result.Friends.Count];
    And I think this is wrong:
    FriendInfo = result.Friends;
    and I would change this:
    PlayFab.ClientModels.FriendInfo friendInfo = result.Friends.ElementAt(i);
    to:
    PlayFab.ClientModels.FriendInfo friendInfo = result.Friends[i];
  • avimon
    avimon
    edited July 2018
    @JohnTube Thanks a lot. You saved my day. I got it worked. I will report to you if I face any other issue. Thanks again.