【问题标题】:Get a user ID from Google Play Services?从 Google Play 服务获取用户 ID?
【发布时间】:2014-10-16 20:45:42
【问题描述】:

在使用 Google Play 服务时,我们有什么方法可以从特定用户那里获取 Google Play ID(数字、字符串等)?

【问题讨论】:

    标签: android google-play google-play-services


    【解决方案1】:

    对于 Google Play 游戏服务,您可以使用:

    String playerId = Games.Players.getCurrentPlayerId(getApiClient());
    

    【讨论】:

    • 我想通了,但谢谢。这可能对将来的其他人有所帮助。
    • @Pygmalion 它是独一无二的且不变的吗?可以用来保存玩家在线进度吗?
    【解决方案2】:

    这取决于您尝试访问的服务。 这是 Google Play 游戏的相关课程 Playerhttps://developer.android.com/reference/com/google/android/gms/games/Player.html

    还有来自 Google Plus 的相关课程 Peoplehttps://developer.android.com/reference/com/google/android/gms/plus/model/people/package-summary.html

    最后,还有用于 Google 移动广告平台的 AdvertisingIdClienthttps://developer.android.com/reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.html

    【讨论】:

    • 是的,我不想向用户询问 G+ 权限。我只想要用户ID。我不知道如何进入这个“播放器”课程。
    • com.google.android.gms.games.Player 就在第一个链接上。
    • 所以只需导入它就可以了?我得到用户的ID?我还需要做什么吗?
    • 我注意到玩家 ID 是一个字符串,而不是一个整数。如果用户没有设置播放器字符串 ID 怎么办?我只希望他们在 Google Play 服务中的用户 ID....
    • 好的。所以我知道我需要import com.google.android.gms.games.Player;SOMETHING.getPlayerId();.. 你能告诉我:什么是什么???
    【解决方案3】:

    所以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();
    }
    

    【讨论】:

      【解决方案4】:

      我相信,上面的答案我们已经过时了。试试这个:

      var playerID = PlayGamesPlatform.Instance.localUser.id
      

      【讨论】:

        猜你喜欢
        • 2023-04-04
        • 2014-04-16
        • 1970-01-01
        • 1970-01-01
        • 2015-05-31
        • 1970-01-01
        • 2018-10-09
        • 2016-04-08
        • 1970-01-01
        相关资源
        最近更新 更多