在使用Google Play Services时,有没有任何方式可以从特定用户处获得Google Play ID(数字、字符串或其他内容)?
在使用Google Play Services时,有没有任何方式可以从特定用户处获得Google Play ID(数字、字符串或其他内容)?
对于Google Play游戏服务,您可以使用:
String playerId = Games.Players.getCurrentPlayerId(getApiClient());
Player
:
https://developer.android.com/reference/com/google/android/gms/games/Player.html
而与 Google Plus 相关的类为 People
:
https://developer.android.com/reference/com/google/android/gms/plus/model/people/package-summary.html
最后,适用于 Google Mobile Ads 平台的是 AdvertisingIdClient
:
https://developer.android.com/reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.html
Player
就是你想要的。据我所知,它与账户匹配,并且不是用户设置的,而是与 Google 账户绑定的。 - Sam12345因此,Games.Players
类已被弃用,而且没有人提供了一个总结性的解决方案来获取整个玩家对象,从而允许获取玩家ID。以下是我整理出的内容:
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();
}
var playerID = PlayGamesPlatform.Instance.localUser.id