Usage examples
This page shows, step by step, how to apply 'Account linking' to your app's screens. It uses the example of a user who starts as a guest, links a Google account, and later unlinks a login method they no longer use. For the parameters and responses of each method, see Link accounts and get linked login methods and Unlink accounts.
1. Link an account
A user who started as a guest has no way to get back to their play data if they lose their device. If the app guides the user to link a Google account, the user can log in with the same Player ID on other devices and keep using the same play data.
- The user selects Link Google account on the Settings > Account screen of the app.
- The app client authenticates with the Google login Add-on and receives
ProviderUserIdandProviderToken. For how to authenticate, see Sign in with Google. - The app client calls
LinkProviderAsync()with the two values received in step 2. - Handle the screen according to the returned result.
Success: Show a message that linking is complete, and change the Google item in the linking list to the linked state. Because the first link invalidates the guest token, also delete the guest token stored on the device at this point.ProviderOwnedByOther: The Google account you are trying to link is already used by another Player ID. Continue with the flow in Handle account linking conflicts.ProviderTypeAlreadyExists: Another Google account is already linked to this account. Guide the user to unlink the existing link and try again.- For other results, see the response status in Link accounts and get linked login methods.
2. Unlink an account
Unlink when the user wants to clean up accounts they no longer use, or wants to cut the link because the account is at risk of being compromised. This example uses a user who has linked both Google and X accounts and unlinks only the X account.
- The user selects Unlink for the linked X item on the Settings > Account screen.
- The app client shows a message asking the user to confirm the unlinking, and when the user confirms, it calls
UnlinkProviderAsync()withProvider.XinProviderId. - Handle the screen according to the returned result.
Success: Return the X item in the linking list to the unlinked state. The Google account remains linked, so the user can continue to log in.LastProviderUnlinkBlocked: Unlinking would leave no method to log in with. Guide the user to link another login method first.- For other results, see the response status in Unlink accounts.
Related documents
- Link accounts and get linked login methods:
LinkProviderAsync()parameters and responses - Unlink accounts:
UnlinkProviderAsync()parameters and responses - Handle account linking conflicts: Handling after
ProviderOwnedByOther