question

Kim Strasser avatar image
Kim Strasser asked

Issues with linking a device Id to an existing account

I want to link an iOS device to an existing PlayFab account. The account is a recoverable account and the player uses username and password to make the log in.

I call LoginWithPlayFab and after the player is logged in I call GetPlayerCombinedInfonew(). But something is wrong with my code because result.Result.InfoResultPayload.AccountInfo.IosDeviceInfo.IosDeviceId is always null.

Why is it null?

I want to find out if "IosDeviceId" is already linked to the player's account or not. If not, then I want to add the current device Id(PlayerDeviceId) to the player's account if this device Id is not yet linked to another player's account.

What happens if the device Id(PlayerDeviceId) is already linked to another player's account? Is it possible to unlink the device Id from that account and link it afterwards to this account?

How can I unlink a device Id?

What happens if the device Id(PlayerDeviceId) is already linked to another player's account and if I use ForceLink = true in LinkIOSDeviceID?

public async void GetPlayerCombinedInfonew()
{
    await GetPlayerCombinedInfo();
}

private async Task GetPlayerCombinedInfo()
{
    var result = await PlayFabClientAPI.GetPlayerCombinedInfoAsync(new GetPlayerCombinedInfoRequest()
    {
        PlayFabId = PlayerPlayFabID,
        InfoRequestParameters = new GetPlayerCombinedInfoRequestParams()
        {
            GetUserAccountInfo = true
        }
    });

    if (result.Error != null)
        Console.WriteLine(result.Error.GenerateErrorReport());
    else
    {
        if (result.Result.InfoResultPayload.AccountInfo.IosDeviceInfo.IosDeviceId == PlayerDeviceId)
            Console.WriteLine("DeviceId already bound to this account: " + result.Result.InfoResultPayload.AccountInfo.Username);
        else
            //Bind the device to this account if the device is not yet bound to another player's account:
            await LinkiOSDeviceID();
    }
}

private async Task LinkiOSDeviceID()
{
    var result = await PlayFabClientAPI.LinkIOSDeviceIDAsync(new LinkIOSDeviceIDRequest()
    {
        DeviceId = PlayerDeviceId,
        ForceLink = false
    });

    if (result.Error != null)
        Console.WriteLine(result.Error.GenerateErrorReport());
    else
    {
        if (result.Result.ToString() == "true")
            Console.WriteLine("Linking DeviceId to this account was successful.");
        else
            Console.WriteLine("Linking DeviceId to this account was not successful.");
    }
}
Account Management
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 @Kim Strasser,

>>I call LoginWithPlayFab and after the player….Why is it null?

If a player isn’t already linked to a IOS Device, then such info won’t be returned, here is a sample response when a player isn’t linked to IOS Device:

"InfoResultPayload":
{

"AccountInfo":
{
…
}
},

…
},

"CustomIdInfo":
{

"CustomId":"221"
}

},

If the player is linked to a IOS device, then the response would be like:

"InfoResultPayload":
{
…
},

"PrivateInfo":
{},

"IosDeviceInfo":
{

"IosDeviceId":
"111111111111111111111111111"

},
…
},

Therefore, it’s possible that the player isn’t linked to an IOS device yet.

>>I want to find out if "IosDeviceId" is ….What happens if the device Id(PlayerDeviceId) is already linked to another player's account? Is it possible to unlink the device Id from that account and link it afterward to this account?

If the Device ID is already linked to another player’s account, you cannot link it to the current player. And yes, you can unlink the Device Id from that account and link it to the current account.

>>How can I unlink a device Id?

For unlinking IOS device, you can utilize UnlinkIOSDeviceID to unlink the specified device ID. There are also other Linking/Unlinking APIs for other Platforms and most of them are only available in Client API set.

>>What happens if the device Id(PlayerDeviceId) is already linked to another player's account and if I use ForceLink = true in LinkIOSDeviceID?

PlayFab will unlink the device id from other player’s account and re-link it to the current player’s account.

By the way, PlayFab offers Postman collection, which is extremely helpful when debugging and testing certain functions. You can follow the tutorial to get started.

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.

Kim Strasser avatar image Kim Strasser commented ·

Is it necessary that there is always a device linked to an account? I found out that I can log in to my account even if the device is not linked to that account.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Kim Strasser commented ·

No, a device does not necessarily have to be linked to an account. You can still log in to that account if you provide a valid username and password. Here is a doc that talks about login basics you may find helpful: Login basics and best practices

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser Citrus Yan commented ·
For iOS devices, the player ID changes if they uninstall your game, and then re-install it.
https://docs.microsoft.com/en-us/gaming/playfab/features/authentication/login/login-basics-best-practices

What happens to linked iOS/Android devices if a player uninstalls the game before he sells his iOS/Android device and if the buyer re-installs the game?

I think on iOS it should not be possible to log in with LoginWithIOSDeviceID to the player's account after the buyer re-installs the game because the player ID changes.

But what about Android devices? Will the player ID change on an Android device if another player re-installs the game?

Is it possible that the buyer can log in to the player's account if he uses LoginWithAndroidDeviceID because the device is still linked to the player's account?

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.