question

Danish A Nathani avatar image
Danish A Nathani asked

Friends of Friends

Hello, I am making a similar kind of Follower and Following system in my game. What I want is like Player A follows Player B and then Player B sees and follows back Player A. Therefore, both should have the ability to check who their mutual friends are and who they are following or being followed by. Hence, is there a way to get FriendList of another Playfab user via Cloudscript or any?

Player Dataunity3dCloudScriptFriends
10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

[Edited]>> Player A follows Player B and then Player B sees and follows back Player A.

PlayFab doesn't provide the feature to get the followers of the specific player, the API GetFriendsList can only list the players who they are following. So, if you want to implement this feature to display the players' followers, you need to set the followers’d PlayerIds as the Read-Only Player Data. For example, when Player A follows Player B, Player A should trigger a CloudScript function to write its Player Id in the Read-Only Data of Player B. Then Player B can check

>> Therefore, both should have the ability to check who their mutual friends are and who they are following or being followed by. Hence, is there a way to get FriendList of another Playfab user via Cloudscript or any?

As the above answer said, you can call the Server API GetFriendsList on the Cloud Script to get the friend list of players (who they are following) other than the caller. And you call the API GetUserReadOnlyData to get the player's followers.

10 |1200

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

Danish A Nathani avatar image
Danish A Nathani answered

Sorry for the late reply, I was working on the other aspect of the game.

I am not good in Javascript, it would be very helpful if you could write the cloud script code for me.

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.

Sarah Zhang avatar image Sarah Zhang commented ·

You can refer to the document -- How to modify read-only or internal player data from CloudScript - PlayFab | Microsoft Docs to set the read-only player data in the CloudScript. To get the friend list in the Cloud Script, the code could be something like this.

var updateUserDataResult = server.GetFriendsList({

//Replace the currentPlayerId to the PlayFabID of the corresponding player
    PlayFabId: currentPlayerId
  });
1 Like 1 ·
Sarah Zhang avatar image Sarah Zhang Sarah Zhang commented ·

You can also refer to the following threads for more details about how to implement the two-way friend system.

Two-way friend confirmation with Cloud Script - Playfab Community

Friend system clarifications - Playfab Community

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.