question

HackerTester avatar image
HackerTester asked

Server.AddFriend with DisplayName. Can we Use DisplayName Instead of PlayFabId

I just wanted to use Display name or username to do add friend using cloudscript.

// Code That i want some kind of maybe--

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.FriendPlayFabId,
      FriendDisplayName: DisplayName, 
      Tags: ["requester"]});
      
      server.SendPushNotification({
      Recipient: args.friendDisplayName,
      Message: "Nice to meet you"});} 
1 comment
10 |1200

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

HackerTester avatar image HackerTester commented ·
@Rick Chen

Please Help me I really wanted my friend system to do all things with DisplayName

0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

No, we don’t support to use the Display Name to define the current player who is adding the friend. In the API request body of Add Friend, it’s only allowed to use the filed – PlayFabId to represent the player who is adding the friend. As you used in the third statement, you can use the predefined variable currentPlayerId to obtain the requester’s PlayFabId. You can also use the currentPlayerId in the other statements, so requesters don’t need to provide their own PlayFabIDs manually. Besides, the request body of the Add Friend only contains the field -- FriendTitleDisplayName, there is no field -- FriendDisplayName.And in the request body of SetFriendTags, there is also no field – FriendDisplayName. You can only use the FriendPlayFabId in the API SetFriendTags. Please check the documentation Add Friend, Set Friend Tags for more information.

According to your description, you also would like to let the friend add the caller as a friend, is it right? If so, you have to provide the friend player Id to the CloudScript function to call the API Add Friend. If the caller only knows the friend’s title display name, you can call the Client API GetAccountInfo to retrieve the specific PlayFabId through the TitleDisplayName, then pass the friend player Id as the argument to CloudScript. If so, the CloudScript function could be something like this.

handlers.SendFriendRequest = function(args, context){ 
    var result = server.AddFriend({
    PlayFabId: currentPlayerId,
    FriendPlayFabId: args.friendPlayerId});

    var result = server.SetFriendTags({ 
    FriendPlayFabId: args.friendPlayerId,   
    Tags: ["requestee"]});
    
    var result = server.AddFriend({
    PlayFabId: args.friendPlayerId,
    FriendPlayFabId: currentPlayerId});

    var result = server.SetFriendTags({
    FriendPlayFabId: currentPlayerId, 
    Tags: ["requester"]});
} 

In addition, could you please clarify that why you only want to use the display name to do all thing about friend adding? And how do you get the friend’s display name? In general, if you can get the DisplayName, you can also obtain the PlayFabId. The PlayFabId is designed as the unique identifier for the player, our APIs always use it to identify a player.

5 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.

HackerTester avatar image HackerTester commented ·

@Rick Chen yeah exactly after sometime It figured out on my own also that i could retrieve the playfab id of anyone using the username and then pass in the playfab id's of the needed players, Thanks and Playfab Community is actually a really good way to get and tell ans, i like how quick u people are and how to the point your ans is so thanks i got the ans and this post might help more beginners like me

0 Likes 0 ·
HackerTester avatar image HackerTester HackerTester commented ·

@Sarah Zhang Oops sorry i typed the Rick Chen Instead of your name from this i got another question arise in mind is it possible to edit my post i read one thread on this and saw that playfab would apply this feature if it get voted, So did this feature got enough votes so that playfab community could have this basic feature cause i think its an important one...

0 Likes 0 ·
HackerTester avatar image HackerTester commented ·
@Rick Chen

yeah i knew there was nothing like friendDisplayName,etc i was just trying to explain u my need and what i wanted to do and u exactly told me the solution that i can get their playfab id using username and then just pass them. Thanks

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang HackerTester commented ·

You can call the Client API GetAccountInfo in the client to obtain the PlayFabId according to the TitleDisplayname, the request body can be something like this.

{
  "TitleDisplayname": "testname"
}
0 Likes 0 ·
HackerTester avatar image HackerTester Sarah Zhang commented ·

@Sarah Zhang Yeah thats what i am exactly doing thanks for help

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.