question

marcoballante avatar image
marcoballante asked

UNTY: why LoginWithCustomID set logged and LoginWithFacebook not

hi, if i log like this:

 PlayFabClientAPI.LoginWithCustomID(
            // Request
            new LoginWithCustomIDRequest
            {
                CustomId = SystemInfo.deviceUniqueIdentifier,
                CreateAccount = true
            },
            // Success
            result =>
            {
                Debug.Log("Login completed.");
                IsLoggedIn = true;
                onSuccess(result);
            },
            // Failure
            error =>
            {
                Debug.LogError("Login failed.");
                Debug.LogError(error.GenerateErrorReport());
                onFailed(error);
            }
        );
everithing working, but, if I log like this:

  //      PlayFabClientAPI.LoginWithFacebook(
  //           // Request
  //           new LoginWithFacebookRequest
  //           {
  //               TitleId = PlayFabSettings.TitleId,
  //               AccessToken = Facebook.Unity.AccessToken.CurrentAccessToken.TokenString,
  //               CreateAccount = true
  //           },
  //           // Success
  //           result =>
  //           {
  //               Debug.Log("Login completed.");
  //               IsLoggedIn = true;
  //               onSuccess(result);
  //           },
  //           // Failure
  //           error =>
  //           {
  //               Debug.LogError("Login failed.");
  //               Debug.LogError(error.GenerateErrorReport());
  //               onFailed(error);
  //           }
  //       );

i get this error:

PlayFabException: Must be logged in to call this method

when i call:

        GetAccountInfoRequest request = new GetAccountInfoRequest();
        PlayFabClientAPI.GetAccountInfo(request, SuccessGetId, fail);


Why it's appening? and how can i fix this?
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

·
Seth Du avatar image
Seth Du answered

I cannot reproduce your issue, however, it is possible that you are doing multiple APIs at the same time.

Because in Unity SDK, PlayFab API calls are all asynchronous. If a series of APIs are called at the same time, make sure the calls afterwards are written in the success callback functions of login API. Otherwise, you may need to use coroutine to wait for few seconds to make sure the properties in authentication context have been initialized and assigned properly.

Here is an example:

PlayFabClientAPI.LoginWithFacebook(
            new LoginWithFacebookRequest {
                AccessToken = "xxxxxxxxxx",
                CreateAccount = true,
                TitleId = "xxxx"
            },
            loginSuccess=> { 
                print("loginsuccess");
                PlayFabClientAPI.GetLeaderboard(
                    new GetLeaderboardRequest {
                    MaxResultsCount = 20,
                    StartPosition = 0,
                    StatisticName = "xxxxxx"
                    },
                    getSuccess=> { print(PlayFabSimpleJson.SerializeObject(getSuccess.Leaderboard)); },
                    getFailed=> { print(getFailed.GenerateErrorReport()); });
            },
            Loginfailed=> { print(Loginfailed.GenerateErrorReport()); });
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.