question

Matt avatar image
Matt asked

AzureFunction error trying to get UserData

Hey folks,

My cloudscript Azure Function is failing with an error due to this specific line of code:

PlayFabResult<GetUserDataResult> userData = await PlayFabServerAPI.GetUserDataAsync( new GetUserDataRequest() { PlayFabId = currentPlayerId, Keys = new List<string>() { "global" } } );

I'm trying to get the player's UserData, but for some reason this line errors out. I noticed someone post in the forums with a similar problem, and he was told to Wait on the returned task. My function doesn't seem to return a task, but instead a PlayFabResult which cannot be waited on.

Any help would be much appreciated, I'm almost through this nightmare that is Azure Functions.

-Matt

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.

Sarah Zhang avatar image Sarah Zhang commented ·

Firstly, could you please clarify why you would like to use the Server API to get the User Data on the Azure Functions? Just for clarification, the User Data can be read and written by Client API GetUserData directly. And the User Read-Only Data can also be retrieved from the Client API GetUserReadOnlyData directly, and need to be written by the server API.

We would suggest you store the data that players are not allowed to read and write in the user internal data. Do you need the C# Azure Functions sample code to call the GetUserInternalData?

0 Likes 0 ·
Matt avatar image Matt Sarah Zhang commented ·

Thanks for the reply. To be honest, I simply adopted the use of the server API from my previous title using the legacy cloudscripting system. I simply changed server to PlayFabServerAPI, but as you mention, I certainly don't need to use the server from my Azure Functions.

I will happily change the code to use the Client API, though I'm curious if there's any reason to do so. For me, on my end, I don't really care which API does it, as long as it gets done, right?

Either way, the problem I have listed above is the same since the call to the PlayFabClientAPI.GetUserDataAsync is identical. Could you please provide me the updated way to perform this action? I swear I keep ending up on outdated tutorials on github.

Thanks again.

P.S. - The answer to your last question is a resounding yes. I have other forum questions asking for assistance (specifically current code samples doing the basic actions of getting arguments, making API calls, and returning objects) such as here.

0 Likes 0 ·
Matt avatar image Matt Sarah Zhang commented ·

Also, I notice the ClientAPI doesn't take in a player Id...how would that work from within the Azure Functions if there's no currently logged in player?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Matt commented ·

Client API needs a valid session ticket to make the call, while the session tickets contain the player identity stored in PlayFab server for verification.

If this function needs to apply actions to other players, target players' IDs should be passed through function arguments.

0 Likes 0 ·

1 Answer

JayZuo avatar image
JayZuo answered

Please check the answer here: https://community.playfab.com/answers/60117/view.html. It shows how to get player statistics. User data is similiar.

10 |1200

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