Is there any way that we can get a Google Play ID (number, string, whatever) from a particular user when utilizing Google Play Services?
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.
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.
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();
}
For Google Play Game Services you can use:
String playerId = Games.Players.getCurrentPlayerId(getApiClient());
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With