【发布时间】: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