【发布时间】:2014-10-16 20:45:42
【问题描述】:
在使用 Google Play 服务时,我们有什么方法可以从特定用户那里获取 Google Play ID(数字、字符串等)?
【问题讨论】:
标签: android google-play google-play-services
在使用 Google Play 服务时,我们有什么方法可以从特定用户那里获取 Google Play ID(数字、字符串等)?
【问题讨论】:
标签: android google-play google-play-services
对于 Google Play 游戏服务,您可以使用:
String playerId = Games.Players.getCurrentPlayerId(getApiClient());
【讨论】:
这取决于您尝试访问的服务。
这是 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
【讨论】:
com.google.android.gms.games.Player 就在第一个链接上。
import com.google.android.gms.games.Player; 和SOMETHING.getPlayerId();.. 你能告诉我:什么是什么???
所以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
【讨论】: