【问题标题】:Google Play Games API and ScopeGoogle Play 游戏 API 和范围
【发布时间】:2026-02-24 23:20:04
【问题描述】:

很长时间以来,我一直在努力为我的问题找到一个好的答案。 我的问题有点简单。

在访问 Google Play Games API 时,Google 建议我们不要要求不必要的范围。

this post, 中,无需同意屏幕即可访问 API 的好方法是这样的:

 // This way you won’t get a consent screen  
 GoogleApiClient gac = new GoogleApiClient.Builder(this, this, this)  
           .addApi(Games.API)  
           .build();  
 // This way you won’t get a consent screen  

Play Game Services Guide,他们给出了这个例子

// Create the Google Api Client with access to the Play Games services
mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(Games.API).addScope(Games.SCOPE_GAMES)
        // add other APIs and scopes here as needed
        .build();

所以我的问题是关于“addScope(Games.SCOPE_GAMES)”。添加它时,用户会获得一个同意屏幕,其中包含年龄范围、游戏玩家资料以及我不太记得的类似内容。

它是干什么用的?两者有什么区别? 如果我不使用它并且只使用 addApi(Games.API) 而不添加范围,我无法访问什么

我的游戏只需要显示多人游戏的玩家用户名和玩家 ID。我需要添加范围吗?因为我真的不想在登录时显示同意窗口。

谢谢。

【问题讨论】:

    标签: api service scope google-play-games


    【解决方案1】:

    正如Google Play Docs 所述,包括getCurrentAccountName() 在内的一些功能需要SCOPE_GAMES。因此,如果您想显示您的玩家用户名,您需要添加范围。 (另外,对于用户名,需要权限:android.permission.GET_ACCOUNTS

    【讨论】:

    • 感谢您的回答 :) 我通过 getCurretPlayer().displayName(); 获得了用户名它工作正常。所以我想我不需要 get_accounts 权限,只需要范围。