我正在尝试为 Android 游戏设置 Google 登录。登录工作正常,我可以选择一个 Google 帐户并登录。但是在调用排行榜时,它向我显示错误:当前登录的 Google 帐户中缺少 Games.SCOPE_GAMES_LITE 范围。 所以我一直在尝试在登录时请求这个范围——但如果我这样做了,之前来自谷歌的登录对话框就不会再出现了。它没有给我任何错误,它只是不显示。 (同样,如果我尝试将 DEFAULT_SIGN_IN 更改为 DEFAULT_GAMES_SIGN_IN。)有什么想法吗?以前在这里问过类似的问题,但目前还没有好的答案......
public class SignInFragment extends Fragment {
private GoogleSignInOptions options;
private GoogleSignInClient client;
SignInButton signInButton;
private Intent signInIntent;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View signInFragment = inflater.inflate(R.layout.fragment_signin, container, false);
options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestScopes(Games.SCOPE_GAMES_LITE)
.build();
client = GoogleSignIn.getClient(this.getActivity(), options);
signInButton = (SignInButton) signInFragment.findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_WIDE);
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});
return signInFragment;
}
private void signIn() {
signInIntent = client.getSignInIntent();
startActivityForResult(signInIntent, StaticResources.RC);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == StaticResources.RC) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
updateUI(account);
} catch (ApiException e) {
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
updateUI(null);
}
}
private void updateUI(GoogleSignInAccount account){
//...
}
}
这就是我得到有关缺少范围的错误的地方:
private void showScores(){
// If user did sign in previously, this returns the user's Google account
if (StaticResources.thisAccount != null){
Games.getLeaderboardsClient(this.getActivity(),
GoogleSignIn.getLastSignedInAccount(this.getContext()))
.getLeaderboardIntent(getString(R.string.leaderboard_highscore))
.addOnSuccessListener(new OnSuccessListener<Intent>() {
@Override
public void onSuccess(Intent intent) {
startActivityForResult(intent, StaticResources.RC);
}
});
}
else{ //...
最佳答案
我发现了问题...我的 gradle 文件很好,但是我的 list 文件中缺少这个:
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
您可以在登录 Google Play 控制台时找到您的 App ID --> 游戏服务 --> “您的游戏” --> “游戏详情”,直接在标题(这是您的应用名称)下
关于android - Google 登录 - 如何添加 Games.SCOPE_GAMES_LITE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51401533/