question

Reason Random avatar image
Reason Random asked

how to display friend list Because i want to send friend request??

i want to display a friend list??

image:

i have 15 player

i want to send a request player1->player2 before display a friend list??

i alreay login successfully.

Code:

PlayFabLogin.cs

    List<FriendInfo> _friends = null;

    public void Login(string username, string password)//login(2)
    {
        LoginWithPlayFabRequest request = new LoginWithPlayFabRequest();
        //playerprefs for login
        //PlayerPrefs.GetString("Username", username);
        PlayerPrefs.GetString("Password", password);
        PlayerPrefs.GetString("Email", username);
        request.Username = username;
        request.Password = password;


        PlayFabClientAPI.LoginWithPlayFab(request, OnLoginSuccess, OnError);


        DisplayFriends(_friends); //when player login then display a friend list
        GetFriends();
    }


    void DisplayFriends(List<FriendInfo> friendsCache)
    {
        friendsCache.ForEach(f => Debug.Log(f.FriendPlayFabId));
    }


    void DisplayPlayFabError(PlayFabError error)
    {
        Debug.Log(error.GenerateErrorReport());
    }
    void DisplayError(string error)
    {
        Debug.LogError(error);
    }


    void GetFriends()
    {
        PlayFabClientAPI.GetFriendsList(new GetFriendsListRequest
        {
            IncludeSteamFriends = false,
            IncludeFacebookFriends = false
        }, result => {
            _friends = result.Friends;
            DisplayFriends(_friends); // triggers your UI
        }, DisplayPlayFabError);
    }

code:

PlayFabSharedSettings.cs

using UnityEngine;
using PlayFab;


#if UNITY_5_3_OR_NEWER
[CreateAssetMenu(fileName = "PlayFabSharedSettings", menuName = "PlayFab/CreateSharedSettings", order = 1)]
#endif
public class PlayFabSharedSettings : ScriptableObject
{
    public string TitleId="";                             //here which title id enter
  
    internal string VerticalName = null;
    #if ENABLE_PLAYFABSERVER_API || ENABLE_PLAYFABADMIN_API || UNITY_EDITOR
        public string DeveloperSecretKey;
    #endif
        public string ProductionEnvironmentUrl = "";


    #if UNITY_2017_2_OR_NEWER
        public WebRequestType RequestType = WebRequestType.UnityWebRequest;
    #else
        public WebRequestType RequestType = WebRequestType.UnityWww;
    #endif


    public string AdvertisingIdType;
    public string AdvertisingIdValue;


    public bool DisableAdvertising;
    public bool DisableDeviceInfo;
    public bool DisableFocusTimeCollection;


    public int RequestTimeout = 2000;
    public bool RequestKeepAlive = true;
    public bool CompressApiData = true;


    public PlayFabLogLevel LogLevel = PlayFabLogLevel.Warning | PlayFabLogLevel.Error;
    public string LoggerHost = "";
    public int LoggerPort = 0;
    public bool EnableRealTimeLogging = false;
    public int LogCapLimit = 30;
}


Push Notifications
15-player.png (23.2 KiB)
10 |1200

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

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Hi, you can use AddFriend API to add a friend. For instance, Player A calls AddFriend with Player B's PlayFabId as the parameter, Player B will be added to Player A's friend list when this operation is completed, Player A can call GetFriendList to get all his friends. However, there is something you need to know about, the Friend System in PlayFab is more like a “follow system” which does not require two-way confirmation which means that Player A is not listed in Player B's friend list and there is no option for Player B to accept the friend request Player A sent. However, in this thread Brendan created provides a way to enable a two-way friend system with no contention issues to deal with. You can check it out:)

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.