首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌登录-如何添加Games.SCOPE_GAMES_LITE?

谷歌登录-如何添加Games.SCOPE_GAMES_LITE?
EN

Stack Overflow用户
提问于 2018-07-18 20:01:45
回答 0查看 535关注 0票数 3

我正在尝试设置一个Android游戏的谷歌登录。登录工作正常,我可以选择一个Google帐户并登录。但在调用排行榜时,它显示了一个错误:当前登录的谷歌帐户中缺少Games.SCOPE_GAMES_LITE作用域。因此,我一直试图在登录时请求此范围-但如果我这样做了,谷歌之前工作的登录对话框就不会再出现了。它没有给我任何错误,它只是没有显示出来。(如果我尝试将DEFAULT_SIGN_IN更改为DEFAULT_GAMES_SIGN_IN,也是如此。)有什么想法吗?类似的问题以前也在这里被问过,但到目前为止还没有好的答案。

代码语言:javascript
复制
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){
    //...
}
}

这就是我得到关于缺少作用域的错误的地方:

代码语言:javascript
复制
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{ //...
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51401533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档