I was learning to make friends in Unity using PlayFab and i wanted to do it with a friend request confuimation. I have seen many community posts but i found that they all are posted long time ago. I wanted to know whether any such feature has been added or not else is there any other way to do it, if any please explain it with an example code as I am new too coding and PlayFab and I believe that PlayFab community is highly responsive with valuable answers. Thank you in advance.
Answer by Rick Chen · Nov 16, 2020 at 06:46 AM
Currently adding friends in PlayFab is a one way process. Players can add other players to their own friend list without the needs of other players’ confirmation.
There is a workaround to implement two-way friend confirmation with Cloud Script:
handlers.SendFriendRequest = function(args, context){ server.AddFriend( { PlayFabId: currentPlayerId, FriendPlayFabId: args.FriendPlayFabId }); server.SetFriendTags({ PlayFabId: currentPlayerId, FriendPlayFabId: args.FriendPlayFabId, Tags: ["requestee"] }); server.AddFriend( { PlayFabId: args.FriendPlayFabId, FriendPlayFabId: currentPlayerId }); server.SetFriendTags( { PlayFabId: args.FriendPlayFabId, FriendPlayFabId: currentPlayerId, Tags: ["requester"] }); server.SendPushNotification({ Recipient: args.FriendPlayFabId, Message: "Nice to meet you" });}
handlers.AcceptFriendRequest = function(args, context){ server.SetFriendTags({ PlayFabId: currentPlayerId, FriendPlayFabId: args.FriendPlayFabId, Tags: ["confirmed"] }); server.SetFriendTags( { PlayFabId: args.FriendPlayFabId, FriendPlayFabId: currentPlayerId, Tags: ["confirmed"] });}
handlers.DenyFriendRequest = function(args,context){ server.RemoveFriend({ PlayFabId: currentPlayerId, FriendPlayFabId: args.FriendPlayFabId, }); server.RemoveFriend( { PlayFabId: args.FriendPlayFabId, FriendPlayFabId: currentPlayerId, });}
Please refer to this thread: https://community.playfab.com/questions/370/206712537-Two-way-friend-confirmation-with-Cloud-Script.html
If you are not familiar with Cloud Script, please go through this document: CloudScript quickstart
Is there a way to achieve the above using c# ClientAPI?, as currently AddFriend only add to the local player and there's no clear way to define another PlayFabID.
Cloud script works perfectly! thanks
Hey Please Tell me how the GetFriendWithTag?
Currently, there is no such API. You could use the GetFriendsList API to retrieve all friends with their tags, then filter the target tag on client side.
Can you please give the C# commands needed to run these Cloud scripts. Also now the cloud scripts UI under "Automation" of the Playfab account has changed and there aren't any videos which cover this properly at all. Would you please give some resources to counter this problem...I am stuck in this for the past 5 days
Answer by Mohamed Younes · May 25, 2021 at 01:27 AM
Is there a way to achieve the above using c# ClientAPI.? currently AddFriend only add friend to the local player and there's no option that takes PlayFabID for the player.
No, it is not supposed to allow the client to manipulate other players’ friend list.
Answer by HackerTester · Jul 20, 2021 at 01:47 AM
@Rick Chen Hi, But can we use Display Name or Username to do the same thing i dont want my users to fill in the long playfab id please help.
Answer by HackerTester · Jul 20, 2021 at 01:47 AM
Please help me i wanted to use Username or DisplayName instead of playfab id and also i wanted two way friend confirmation
// Code That i want some kind of maybe-- how can i do it please help @Rick Chen handlers.SendFriendRequest = function(args, context){ server.AddFriend({ DisplayName: DisplayName, FriendDisplayName: args.friendDisplayName}); server.SetFriendTags({ DisplayName: DisplayName, FriendDisplayName: args.friendDisplayName, Tags: ["requestee"]}); server.AddFriend({ DisplayName: args.friendDisplayName, FriendPlayFabId: currentPlayerId}); server.SetFriendTags({ DisplayName: args.friendDisplayName, FriendDisplayName: DisplayName, Tags: ["requester"]}); server.SendPushNotification({ Recipient: args.friendDisplayName, Message: "Nice to meet you"});}
Please navigate to the new thread you posted -- Server.AddFriend with DisplayName. Can we Use DisplayName Instead of PlayFabId - Playfab Community. to discuss this question with us.
Answer by siddhirajrayate741 · Apr 01 at 05:44 AM
How to add a friend on both friend list
please tell me.
thanks.
Cloud Script Return Value Problem - Null Reference Error 1 Answer
Where can I find resources for "best practices" using Cloudscript Functions for coding in C#? 1 Answer
Updating Online / Offline status of player? 1 Answer
How to access the variables of cloud scripts in Unity's C# script ? 0 Answers
ExecuteCloudScript Errors - 'ExecuteCloudScriptResult' does not contain a definition 0 Answers