I get this exception in my client code if I call RegisterPlayFabUser.
PlayFab.PlayFabException has been thrown Must be logged in to call this method
In addition, the new account is not created because I don't get a notification in PlayStream when I try to create the player's account in CloudScript:
Why is the player not logged in if I call RegisterPlayFabUser in CloudScript? What is wrong with my code?
Client code:
private async Task RegisterPlayFabUserCloud() { var result = await PlayFabClientAPI.ExecuteCloudScriptAsync(new ExecuteCloudScriptRequest() { FunctionName = "RegisterPlayFabUser", FunctionParameter = new { SessionTicket = playersessionTicket, Email = "player2test@gmail.com", Username = "Player2username", Password = "Player2password!!!" }, GeneratePlayStreamEvent = true }); if (result.Error != null) Console.WriteLine(result.Error.Error.ToString()); else { if (result.Result.Logs.Count() > 0) Console.WriteLine(result.Result.Logs[0].Message); } }
CloudScript:
handlers.RegisterPlayFabUser = function (args, context) { var resultprofile = server.GetPlayerProfile( { PlayFabID: currentPlayerId }); var result = RegisterPlayFabUserFromCloudScript(args.SessionTicket, args.Email, args.Username, args.Password, currentPlayerId); return result; } function RegisterPlayFabUserFromCloudScript(sessionticket, email, username, password, playFabId) { var contentBodyTemp = { "TitleId": BFD0A, "RequireBothUsernameAndEmail": true, "PlayFabId": playFabId, "Email": email, "Username": username, "Password": password }; let url = "https://BFD0A.playfabapi.com/Client/RegisterPlayFabUser"; let method = "POST"; let contentBody = `{"TitleId": "${BFD0A}", "RequireBothUsernameAndEmail": "${true}", "PlayFabId": "${playFabId}", "Email": "${email}", "Username": "${username}", "Password": "${password}"}`; let contentType = "application/json"; let headers = { "X-Authentication": sessionticket }; let responseString = http.request(url, method, contentBody, contentType, headers); let responseJSONObj = JSON.parse(responseString); return (responseJSONObj); }