question

tinklife avatar image
tinklife asked

GetCharacterInventory results differ. (Client/Server)

 

 

 

 

 

 

I'm testing to use Character's Virtual Currency as 'Status Upgrade'.

 

When I call "GetCharacterInventory" from server, It works fine.

(From Server API Try GetCharacterInventory)

 

But, my client get error messages with no data, so I tried it on "Try It" menu.

(From Client API Try GetCharacterInventory)

Client API always gave me null and I think it's kind of bug.

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

Thanks for calling that out - there does seem to be something wrong with the Try It functionality for that API call, so I'll open a bug with the tools team. If you test using Postman (or your own code) however, you'll see that the two API calls both return the Character inventory no problem, however.

10 |1200

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

tinklife avatar image
tinklife answered

I traced from my client and I got this result.

{"code":200,"status":"OK","data":{"Inventory":[],"VirtualCurrency":{"HP":3,"RG":1,"ST":7},"VirtualCurrencyRechargeTimes":{}}}

which has no "PlayFabId" and "CharacterId".

This causes "Client failed to parse response from server" error in Unity SDK.

[ErrorMessage]

PlayFab.Internal.ResultContainer`1:HandleResults(CallRequestContainer, Delegate, ErrorCallback, Action`2) (at Assets/PlayFabSDK/Internal/ResultContainer.cs:84)
PlayFab.<GetCharacterInventory>c__AnonStorey7E:<>m__1D9(CallRequestContainer) (at Assets/PlayFabSDK/Public/PlayFabClientAPI.cs:1259)
PlayFab.CallRequestContainer:InvokeCallback() (at Assets/Plugins/PlayFabShared/PlayFabErrors.cs:255)
PlayFab.Internal.<MakeRequestViaUnity>c__Iterator13:MoveNext() (at Assets/PlayFabSDK/Internal/PlayFabHTTP.cs:260)

 

 

I tested inserting that 2 Id parts to requestContainer.ResultStr and that error disappeared.

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

Sorry, I don't follow. Which SDK are you using and which version? For example, the GetCharacterInventory API call in our Unity SDK uses a GetCharacterInventoryRequest and GetCharacterInventoryResponse, which do contain the PlayFabId and CharacterId:

https://github.com/PlayFab/UnitySDK/blob/9c89d03df58f44b736da04391586e4d51bc83c5f/PlayFabClientSample/Assets/PlayFabSDK/Public/PlayFabClientModels.cs

 

Can you provide the code snippet showing how you're making this call?

10 |1200

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

tinklife avatar image
tinklife answered

I'm using your official package (downloaded 20160318).

 

I mean your "Server Reponse" has 2 missing variables.

So, for now, I added this line at your code(git link) to walk around.

requestContainer.ResultStr = requestContainer.ResultStr.Replace("\"data\":{",
"\"data\":{\"PlayFabId\":\""+request.PlayFabId+"\",\"CharacterId\":\""+request.CharacterId+"\"");

 

 

I don't think my requesting code is wrong but I'll add anyway. 

for(int i = 0;i < m_Characters.Count;i++)
{
      GetCharacterInventoryRequest request = new GetCharacterInventoryRequest()
      {
              PlayFabId = PlayfabId,
              CharacterId = m_Characters[i].CharacterId,
      };

      PlayFabClientAPI.GetCharacterInventory( request, UpdateSingleCharacterInventory,
     (error) =>
      {
          Debug.Log( string.Format("ERROR {0} ] {1} {2}", error.Error, error.HttpCode, error.HttpStatus) );
     });
}

public void UpdateSingleCharacterInventory(GetCharacterInventoryResult result)
{
if( m_CharacterCurrencies.ContainsKey( result.CharacterId ) )
{
m_CharacterCurrencies[result.CharacterId] = result.VirtualCurrency;
}
else
{
m_CharacterCurrencies.Add(result.CharacterId, result.VirtualCurrency );
}

if( m_CharacterInventory.ContainsKey(result.CharacterId ) )
{
m_CharacterInventory[result.CharacterId] = result.Inventory;
}
else
{
m_CharacterInventory.Add(result.CharacterId, result.Inventory );
}
CharacterInventoryLog();
}
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

Aha - you're absolutely right! Thanks for calling that out. The PlayFabId and CharacterId are not, in fact, returned in the results. For the PlayFabId, this is the same as for the GetUserInventory call, where the PlayFabId is not returned, as the user can only query his own inventory. Since a player could have multiple character though, it does make sense for the CharacterId to be returned. We'll get the code and docs updated to put the CharacterId in the returned data and to remove the PlayFabId from the request (since it's not actually used on the client call).

Meanwhile, you can indeed get the CharacterId from the request data, though here's the code snippet we would recommend using:

 

       public void GetCharacterInventoryCallback(GetCharacterInventoryResult getResult)
       {
           var characterId = ((GetCharacterInventoryRequest)getResult.Request).CharacterId;
           ... etc
       }

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.