I'm newbie about backend and really need help with getuserdata. I have managed to integrate my game with PlayFab's Kongregate Add-on. SetUserData works fine. I can see players saved key/value pairs on my game manager. When I try to copy the GetUserData code sample from documentation, PlayFabId = PlayFabId code line isn't working.
using PlayFab; using PlayFab.ClientModels; using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; public class KongregateHandler : MonoBehaviour { public void Start() { // Utility: show feedback SetMessage("Loading kongregate api..."); /* * Important: execute Javascript in the external context to initialize * Kongregate API, Unity Support and set up callback GameObject and Method. * In this case, callback is set to a GameObject called Kongregate and a * method called OnKongregateAPILoaded, which we define later in this class. * Once Kongregate API is initialized, Unity will locate this object by name * ("Kongregate") and execute a method "OnKongregateAPILoaded" passing in user * info string as an argument. */ Application.ExternalEval( "if(typeof(kongregateUnitySupport) != 'undefined'){" + " kongregateUnitySupport.initAPI('Kongregate', 'OnKongregateAPILoaded');" + "} else {" + " console.error('No unity support!');" + "};" ); } /* * Executed once Kongregate API is ready. This method is invoked by KongregateAPI * and receives a structured text with multiple pieces of data you must parse manually. * The userInfo string parameter has the following structure: 'user_identifier|user_name|auth_token' */ public void OnKongregateAPILoaded(string userInfo) { SetMessage("Recieved user info! Logging though playfab..."); // We split userInfo string using '|' character to acquire auth token and Kongregate ID. var userInfoArray = userInfo.Split('|'); var authTicket = userInfoArray[2]; var kongregateId = userInfoArray[0]; LogToBrowser("Auth Token: " + authTicket); LogToBrowser("Kongregate Id: " + kongregateId); /* * We then execute PlayFab API call called LoginWithKongregate. * LoginWithKongregate requires KongregateID and AuthTicket. * We also pass CreateAccount flag, to automatically create player account. */ PlayFabClientAPI.LoginWithKongregate(new LoginWithKongregateRequest { KongregateId = kongregateId, AuthTicket = authTicket, CreateAccount = true }, OnLoggedIn, OnFailed); } /* * The rest of the code serves as a utility to process results, log debug statements * and display them using Text message label. */ private void OnLoggedIn(LoginResult obj) { SetMessage("Logged in through PlayFab!"); } private void OnFailed(PlayFabError error) { SetMessage("Failed to login in with PlayFab: " + error.GenerateErrorReport()); } private void SetMessage(string message) { InfoLabel.text = message; } private void LogToBrowser(string message) { Application.ExternalEval(string.Format("console.log('{0}')", message)); } public Text InfoLabel; public void SetUserData() { PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest() { Data = new Dictionary<string, string>() { { "damage", karakter.damage.ToString() }, } }, result => Debug.Log("Successfully updated user data"), error => { Debug.Log("Got error setting user data Ancestor to Arthur"); Debug.Log(error.GenerateErrorReport()); }); } public void GetUserData() { PlayFabClientAPI.GetUserData(new GetUserDataRequest() { PlayFabId = PlayFabId, //THIS LİNE ISN'T WORKİNG// Keys = null }, result => { Debug.Log("Got user data:"); if (result.Data == null || !result.Data.ContainsKey("damage")) Debug.Log("No damage"); else Debug.Log("damage: " + result.Data["damage"].Value); }, (error) => { Debug.Log("Got error retrieving user data:"); Debug.Log(error.GenerateErrorReport()); }); } }