question

Juris Zebnickis avatar image
Juris Zebnickis asked

GetUserData does not find existing keys (Unity)

Hi.

I`m baffled and stumped by this here problem: I`m calling the default SetUserData and GetUserData from the 'Using Player Data' page examples and it sets the data alright, but upon checking the retrieved data it does not find the key that the data was set to. At first I tried it in my own code and kept thinking I must be doing something wrong, but after the examples showed the same behaviour, I do not know what to do.

I`m using SDK 2.32.171106, and the same Editor Extensions version.

Here is my code, which produces "No Ancestor key" , so the data is there, but the key "Ancestor" cannot be found even though it is right there. If I call the GetUserData() without doublechecking Data, I get an error: "The given key was not present in the dictionary".

I can also see my data having been set in the PlayFab Player dashboard:

void SetUserDataEx()
	{
		PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest()
		{
			Data = new Dictionary<string, string>() {
			{"Ancestor", "Arthur"},
			{"Successor", "Fred"}
		},
			Permission = UserDataPermission.Public
		},
		result => { Debug.Log("Successfully updated user data"); },
		error => {
			Debug.Log("Got error setting user data Ancestor to Arthur");
			Debug.Log(error.GenerateErrorReport());
		});
	}
void GetUserDataEx()
	{
		PlayFabClientAPI.GetUserData(new GetUserDataRequest()
		{
			PlayFabId = PlayFabID,
			Keys = new List<string>() { "Ancestor", "Successor" }
		}, result => {
			Debug.Log("Got user data:");
			if (result.Data == null)
			{
				Debug.Log("Data is null");
			}
			else if (!result.Data.ContainsKey("Ancestor"))
			{
				Debug.Log("No Ancestor key");
			}
			else Debug.Log("Ancestor: " + result.Data["Ancestor"].Value);
		}, (error) => {
			Debug.Log("Got error retrieving user data:");
			Debug.Log(error.GenerateErrorReport());
		});
	}
apis
untitled.png (11.4 KiB)
10 |1200

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

1 Answer

·
brendan avatar image
brendan answered

I'm not able to reproduce that in my tests of GetUserData and UpdateUserData. Can you provide the specifics of the Title ID, PlayFab ID(s), and data Keys (other than Ancestor and Successor) you're using?

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

Juris Zebnickis avatar image Juris Zebnickis commented ·

Hi, @Brendan!

The PlayFabID is 5322 and it is the same thing as TitleId, no?

I am using on another key in the PlayerData

called "seen".

I am going through the process this morning again:

1) I removed all the PlayerData from the Player dashboard manually.

2) I called the Set code from my project and successfully set the PlayerData.

3) Then I called the corresponding Get part of the code and hardcoded the ID. The result still returns No Ancestor key and none of the for loops have any data in them. I don't understand. The callback being executed means that the request DID reach the servers and came back, correct? What else could possibly be wrong?


void GetUserDataEx()
{
	PlayFabClientAPI.GetUserData(new GetUserDataRequest()
{
	PlayFabId = "5322",
	Keys = new List<string>() { "Ancestor", "Successor" }
},
	GetUserDataCallback,
	OnApiCallError);
}
private void GetUserDataCallback(GetUserDataResult result)
	{
		for (int i = 0; i < result.Data.Count; i++)
		{
			Debug.Log("Got user data:" + i);
		}
		if (result.Data == null)
		{
			Debug.Log("Data is null");
		}
		else if (!result.Data.ContainsKey("Ancestor"))
		{
			Debug.Log("No Ancestor key");
		}
	}

0 Likes 0 ·
brendan avatar image brendan Juris Zebnickis commented ·

No, 5322 is your Title ID. You have two players in that title - one with the two key/value pairs you described: https://developer.playfab.com/en-us/5322/players/5E7D7B04CC008029/data, and one that does not have those key/value pairs: https://developer.playfab.com/en-us/5322/players/D9E36D04038DEA20/data. If you're setting PlayFab ID to 5322 in the call, that definitely won't work. Querying PlayFab ID 5E7D7B04CC008029, the GetUserData query retrieves the data, no problem.

1 Like 1 ·
Juris Zebnickis avatar image Juris Zebnickis brendan commented ·

You, sir are correct and I did not realize I was trying to use my title id as my playfab player id.

Thank you very much.

0 Likes 0 ·
Juris Zebnickis avatar image Juris Zebnickis commented ·

I am not currently using any other data pairs but the ones in the example.

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.