在使用Google Play服务时,我们是否有任何方式可以获取特定用户的Google Play ID(数字,字符串等)?
答案 0 :(得分:22)
对于Google Play游戏服务,您可以使用:
String playerId = Games.Players.getCurrentPlayerId(getApiClient());
答案 1 :(得分:4)
这取决于您尝试访问的服务。
以下是Google Play游戏的相关课程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移动广告平台有AdvertisingIdClient
:
https://developer.android.com/reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.html
答案 2 :(得分:1)
因此不推荐使用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();
}