question

Thomas Bizal avatar image
Thomas Bizal asked

Simply cannot get UpdateUserInternalData and GetUserInternalData to work.

@Brendan

I feel dumb because this must not be TOO complicated with so many people using these features and so few questions/materials online about it, but I simply cannot get these to work.

I can successfully log in to Playfab with an associated PlayFabID (linked with Kongregate). No problems there. However, when I try to save/load data, I am running into problems. I get an "invalid input parameters" every time I try to save a JSON string. So my player data never actually gets updated, and therefore never loaded either.

My save data code looks like this:

// convert this GameManager (all public user data fields) to JSON

public string convertToJson() {
	return JsonUtility.ToJson(this);
}
var updateRequest = new PlayFab.ServerModels.UpdateUserInternalDataRequest(){
	PlayFabId = playFabID,
	Data = newDictionary<string,string>()
	{
		{"UserData", GameManager.Instance.convertToJson()},
	},

};


PlayFabServerAPI.UpdateUserInternalData(updateRequest,(result)=>
	{
		Debug.Log("Set internal user data successful");
	},(error)=>{
		Debug.Log("Got error updating internal userdata:");
		Debug.Log(error.ErrorMessage);
	});

My load data code looks like this:

// update GameManager class (all public user data fields) from JSON to values

public void convertFromJson(string jsonString) {
        JsonUtility.FromJsonOverwrite(jsonString, this);
} 
var getUserDataRequest=new PlayFab.ServerModels.GetUserDataRequest(){
	PlayFabId = playFabID,
};


PlayFabServerAPI.GetUserInternalData(getUserDataRequest,(result)=>{
	Debug.Log("Got the following user internal data:");
	foreach(var entry in result.Data)
	{
		Debug.Log(entry.Key+":"+entry.Value.Value);
		GameManager.Instance.convertFromJson(entry.Value.Value);
	}
	},(error)=>{
		Debug.Log("Got error getting internal user data:");
		Debug.Log(error.ErrorMessage);
	});

I saw something online about a .stringify() function, but I can't seem to use that in my code? But maybe since I am using convertToJson rather than that, that is why I am getting invalid parameters error?

Any help would be greatly appreciated... I have been stuck on this for days and getting insanely frustrated :(

Thanks,

Tom

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.

Thomas Bizal avatar image Thomas Bizal commented ·

Can't figure out how to update original post, but I wanted to add that I am using C# in Unity3d for this game.

Also, the "JsonUtility.ToJson(this);" code correctly writes out all of the GameManager fields and associated data into a nice long JSON string. It all looks fine, just doesn't let me save it to PlayFab servers. I'm so confused as to why not...

0 Likes 0 ·
Thomas Bizal avatar image
Thomas Bizal answered

Nevermind, I figured it out. Sorry to take up your time.

The invalid input parameters was occurring because i was trying to pass in a 13k char string as my JSON save data (tons of user data!). The limit for free version of PlayFab is 10k chars. So I came up with a method to split the string to save internally as 2 pieces. Then, when I load it back in, I piece it back together and call convertFromJson.

10 |1200

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

brendan avatar image
brendan answered

What are the rest of the details of the error message? The "invalid input parameters" error will always have an errorDetails that provides specifics on which parameter is incorrect.

10 |1200

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

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.