question

Andrew Burrow avatar image
Andrew Burrow asked

Returning linked account info from cloud script

I have a cloud script that returns 3 leaderboards with one api call. This works fine and I can deserialize it to 3 seperate GetLeaderboardResult objects. The problem occurs when I include a ProfileConstraints with ShowLinkedAccounts set to true. I get the result back fine but get the following error trying to deserialize it :

InvalidCastException: Invalid cast from 'System.String' to 'System.Nullable`1[[PlayFab.ClientModels.LoginIdentityProvider, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]'

Any help is greatly appreciated.

sdksCloudScriptLeaderboards and Statistics
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

·
Citrus Yan avatar image
Citrus Yan answered

Hi Andrew, I managed to reproduce your issue that InvalidCastException occurs when trying to deserialize CloudScript result with linked account returned. The method I used to deserialize was PlayFabSimpleJson.DeserializeObject, I suspect that you are using it too. However, when I tried to deserialize using PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject, it worked out well. The code is like this:

GetLeaderboardResult getLeaderboardResults = PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject<GetLeaderboardResult>(result.FunctionResult.ToString());

If this is your case, you could try the code below to see if it works. If this is not your case, could you please tell us what SDK are you using and share the code which you are using to deserialize.

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.

Andrew Burrow avatar image Andrew Burrow commented ·

Thanks for that. Was hoping it wasn't something I was doing as everything looked ok. In the mean time I am just making 3 calls with the client API so I can get on. Would be nice to have a solution though to help cut down on calls. Thanks again.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Andrew Burrow commented ·

Hi Andrew, correct me if I am wrong, as far as I am aware, you have to make 3 calls in order to get each leaderboard results so it’s better to directly call them from the client. What I don’t follow is that why you use Cloud Script to return 3 leaderboards. In the Cloud Script, you still need to call GetLeaderboard 3 times, serialize ExecuteCloudScriptResult and then deserialize it into GetLeaderboardResult in your client, which will definitely increase some overhead. Therefore, I think the better way is just making 3 calls from the client, which is the way you are doing now.

0 Likes 0 ·
Andrew Burrow avatar image Andrew Burrow Citrus Yan commented ·

I am new to Playfab to you could be right, but they try to steer you towards using CloudScript as much as possible so I was under the hope/belief that calling CloudScript was only 1 API call as opposed to 3. I know there is a limit of 20 (I think) separate calls that can be made in that one CloudScript call, so maybe I have got that wrong. Could do with some clirification on that.

0 Likes 0 ·
Show more comments

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.