Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a user ID from Google Play Services?

Is there any way that we can get a Google Play ID (number, string, whatever) from a particular user when utilizing Google Play Services?

like image 833
Agamemnus Avatar asked Oct 16 '14 20:10

Agamemnus


People also ask

What is User ID in app?

What is a user ID? A user ID is an ID that follows a specific user. This ID follows a user when they use different devices and is persistent across installs. Typically a user ID is used with apps that require payment outside of an app store or require a login to obtain the user's profile.

How do I change my Google Play Player ID?

Go to your device's main settings menu. Under 'Personal', select your account. To switch accounts, select Remove account. Follow the steps to add another account.


3 Answers

So the Games.Players class is deprecated and nobody gave a summarised solution to get the entire player object that allows to get the player ID, eventually. Here is what I've sorted out:

GoogleSignInAccount account;
PlayersClient playerClient;
Player player;
String playerId;

account = GoogleSignIn.getLastSignedInAccount(this);
if (account == null) {
    // do sign-in here
}

// Later:

playerClient = Games.getPlayersClient(this, account);
Task<Player> playerTask = playerClient.getCurrentPlayer();
player = playerTask.getResult();
if(player != null) {
    playerId = player.getPlayerId();
}
like image 147
Martin Braun Avatar answered Nov 08 '22 18:11

Martin Braun


For Google Play Game Services you can use:

String playerId = Games.Players.getCurrentPlayerId(getApiClient());
like image 34
Pygmalion Avatar answered Nov 08 '22 17:11

Pygmalion


It depends on the service you are trying to access. Here is the relevant class Player for Google Play Games: https://developer.android.com/reference/com/google/android/gms/games/Player.html

And the relevant class People from Google Plus: https://developer.android.com/reference/com/google/android/gms/plus/model/people/package-summary.html

Finally, there is AdvertisingIdClient for the Google Mobile Ads platform: https://developer.android.com/reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.html

like image 33
Sam12345 Avatar answered Nov 08 '22 19:11

Sam12345