question

uncertaintheory avatar image
uncertaintheory asked

I have logged the user in but cannot get their inventory. It says PlayFabException: Must be logged in to call this method.

Here is my code:

public class PlayFabLogin : MonoBehaviour
{
    public void Start()
    {
        var request = new LoginWithIOSDeviceIDRequest { TitleId = "726", DeviceId = SystemInfo.deviceUniqueIdentifier, CreateAccount = true };
        PlayFabClientAPI.LoginWithIOSDeviceID(request, OnLoginSuccess, OnLoginFailure);


    }
    private void OnLoginSuccess(LoginResult result)
    {
        Debug.Log("Congratulations, you made your first successful API call!");


        if(PlayerPrefs.HasKey("firstLogin")==false)
        {
            //load


            //PlayerPrefs.SetInt("firstLogin", 1);
        }
    }


    private void OnLoginFailure(PlayFabError error)
    {
        Debug.LogWarning("Something went wrong with your first API call.  :(");
        Debug.LogError("Here's some debug information:");
        Debug.LogError(error.GenerateErrorReport());
    }


    void LogSuccess(PlayFabResultCommon result)
    {
        var requestName = result.Request.GetType().Name;
        Debug.Log(requestName + " successful");
    }


    void LogFailure(PlayFabError error)
    {
        Debug.LogError(error.GenerateErrorReport());
    }


    void GetInventory()
    {
        PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), LogSuccess, LogFailure);
    }
}
In-Game Economy
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

·
JayZuo avatar image
JayZuo answered

Where and when you call GetInventory method?You can put this method into OnLoginSuccess method so that you can make sure the player has logged in. Besides, you can also add a PlayFabClientAPI.IsClientLoggedIn() method in GetInventory to check if the player has logged in.

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.

uncertaintheory avatar image uncertaintheory commented ·

Its all working now, thanks for the help!

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.