Is there any way that we can get a Google Play ID (number, string, whatever) from a particular user when utilizing Google Play Services?
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
com.google.android.gms.games.Player
It's right on the first link. –
Shelly AdvertisingIdClient
–
Shelly Player
is what you want. To the best of my knowledge, it matches the account, and it is not user-set but tied to the google account. –
Shelly import com.google.android.gms.games.Player;
and SOMETHING.getPlayerId();
.. can you tell me: what is SOMETHING??? –
Sarson 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();
}
I believe, the answers above our outdated. Try this:
var playerID = PlayGamesPlatform.Instance.localUser.id
© 2022 - 2024 — McMap. All rights reserved.