question

plourdegui avatar image
plourdegui asked

LinkFacebookAccount throws error "AccountAlreadyLinked" regardless of the value of ForceLink

I am trying to copy the same logic in the Unicorn Battle for Force-Binding a Facebook account to a PlayFab account having already been linked a another Facebook account.

The logic in Unicorn Battle is:

  1. Try PlayFabClientAPI.LinkFacebookAccount with ForceLink = false
  2. If the call fails with PlayFabErrorCode.AccountAlreadyLinked, prompt the player and ask whether to Force-Bind the Facebook account to the PlayFab account despite being already linked to another Facebook account.
  3. If the player says yes, call PlayFabClientAPI.LinkFacebookAccount with ForceLink = true.

Unicorn Battle throws an AccountAlreadyLinked error again, regardless of the value of ForceLink.

Title ID: F50C

I'm under the impression there's a problem with the API because I didn't change the code from GitHub.

Could you please advise?

Thanks

10 |1200

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

Seth Du avatar image
Seth Du answered

First, may I ask what’s your detailed error code? “AccountAlreadyLinked” and “LinkedAccountAlreadyClaimed” may look similar but “LinkedAccountAlreadyClaimed” means that the Facebook account is already linked to another PlayFab ID, while “AccountAlreadyLinked” means that the PlayFab ID is already linked to a different Facebook ID.

ForceLink is designed for: 1. Current player account is not linked with any Facebook account; 2. The current Facebook Account has linked with other player account. Then you can set it as True to make the Facebook Account unlink the original PlayFab player account and link the current PlayFab player account.

Besides, Please make sure ForceLink in the request is set as a correct value if it is not hard coded.

10 |1200

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

plourdegui avatar image
plourdegui answered

Thanks @SethDu for clarifying. I was trying to prompt the user upon getting a "AccountAlreadyLinked" error whereas I needed to react upon getting a "LinkedAccountAlreadyClaimed" error.

The method below demonstrates the fixed algorithm.

 public IPromise LinkFaceBookToPlayFab(bool forceLink = false)
{
    return new Promise((res, rej) =>
    {
        var request = new LinkFacebookAccountRequest
        {
            AccessToken = AccessToken.CurrentAccessToken.TokenString,
            ForceLink = forceLink
        };

        Debug.Log("Linking Facebook account to PlayFab... (PlayFabClientAPI.LinkFacebookAccount)");
        PlayFabClientAPI.LinkFacebookAccount(request,
            (LinkFacebookAccountResult result) =>
            {
                Debug.Log("Facebook account successfully linked to PlayFab (PlayFabClientAPI.LinkFacebookAccount)");
                PlayerPrefs.SetInt("linkedToFacebook", 1);
                res();
            },
            (PlayFabError error) =>
            {
                if (error.Error == PlayFabErrorCode.LinkedAccountAlreadyClaimed)
                {
                    // Solution as per https://community.playfab.com/questions/26275/linkfacebookaccount-throws-error-accountalreadylin.html
                    TimedPromise.IsTimeoutMechanismSuspended = true;
                    Debug.LogWarning("This Facebook account is already linked to a different game account. " +
                                     "Prompting player: \"Do you want to unlink this Facebook account from the original game account and then link it to this current game account?\"");
                    ShowConfirmationPopupSignal.Dispatch(I2TermCategory.Login.GetTermPath("ForceBindFacebook"), (confirmation) =>
                    {
                        TimedPromise.IsTimeoutMechanismSuspended = false;
                        if (confirmation)
                        {
                            LinkFaceBookToPlayFab(true).Then(res).Catch(rej);
                        }
                        else
                        {
                            rej(new CustomException("Player doesn't want to force-bind Facebook account to PlayFab account", CustomException.ExceptionType.FacebookLoginCancelled));
                        }
                    });
                }
                else if (error.Error == PlayFabErrorCode.AccountAlreadyLinked)
                {
                    rej(new CustomException(error, CustomException.ExceptionType.AccountAlreadyLinked));
                    return;
                }
                else
                {
                    rej(error.ToException());
                }
            });
    });
}
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.