Hi there, I am trying to write a simple Cloud Script Function that uses the Playfab ServerAPI through an Azure Function to add a friend which is written in C#. I am just trying to understand certain concepts at the moment and that is why I am not using the ClientAPI through Unity but rather the ServerAPI in conjunction with Azure Functions. I have gone through the "Hello World" example and can successfully call a cloud script and return a result in Unity.
I don't have an understanding of PlayFab.PlayFabServerAPI.AddFriendAsync method and would like some clarification as to what "Data" needs to be passed into the call and if I am even close to a proper approach. Any information is greatly appreciated!
The error I am getting in Unity is {"result":{},"customData":null,"error":null}
Here is the code I have written as an Azure Function to try to add a friend via a Cloud Script:
namespace NetworkSystem.FriendRequest { public static class FriendRequest { [FunctionName("FriendRequest")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { var context = JsonConvert.DeserializeObject <FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync()); dynamic args = context.FunctionArgument; string friendEmail = string.Empty; if (args != null && args["friendEmail"] != null) { friendEmail = args["friendEmail"]; } var apiSettings = new PlayFabApiSettings { TitleId = Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID", EnvironmentVariableTarget.Process), DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process), }; var serverApi = new PlayFabServerInstanceAPI(apiSettings); var request = new PlayFab.ServerModels.AddFriendRequest { PlayFabId = context.CallerEntityProfile.Lineage.TitlePlayerAccountId, FriendEmail = friendEmail }; var result = await serverApi.AddFriendAsync(request); return result; } } }