请求服务器身份验证代码时,GoogleSignInResult在Android应用中返回DEVELOPER_ERROR [英] GoogleSignInResult returns DEVELOPER_ERROR in Android app when requesting server auth code

查看:380
本文介绍了请求服务器身份验证代码时,GoogleSignInResult在Android应用中返回DEVELOPER_ERROR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照此手册将Google People API连接到Android应用程序: http ://blog.iamsuleiman.com/people-api-android-tutorial-1/

I am connecting Google People API to the Android app following this manual: http://blog.iamsuleiman.com/people-api-android-tutorial-1/

我正在使用以下代码登录:

I am using the following code to sign in:

GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail()
        .requestScopes(new Scope(Scopes.PLUS_LOGIN),
                new Scope(PeopleScopes.CONTACTS_READONLY),
                new Scope(PeopleScopes.USER_PHONENUMBERS_READ))
        .requestServerAuthCode(getString(R.string.google_oauth_client_id), false)
        .build();

    mGoogleApiClient = new GoogleApiClient.Builder(getContext())
            .enableAutoManage(getActivity(), this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, signInOptions)
            .build();

    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent( mGoogleApiClient );
    startActivityForResult( signInIntent, GOOGLE_PLUS_RC_SIGN_IN );

onActivityResult代码为:

The onActivityResult code is:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
    ...
}

我的结果一直是DEVELOPER_ERROR.

I keep getting DEVELOPER_ERROR in result.

该应用程序由我在开发人员控制台中设置的SHA1指纹的代码签名.

The app is signed by the code which SHA1 fingerprint I setup in the developer console.

OAUTH客户端ID来自我应用的"Web客户端" JSON配置.

The OAUTH client ID is taken from the "Web client" JSON configuration of my app.

在Google开发者控制台中启用了所有API

All APIs are enabled in the Google developer console

如果我删除方法.requestServerAuthCode():

If I remove the method .requestServerAuthCode():

    GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestScopes(new Scope(Scopes.PLUS_LOGIN),
                    new Scope(PeopleScopes.CONTACTS_READONLY),
                    new Scope(PeopleScopes.USER_PHONENUMBERS_READ))
            .build();

Auth.GoogleSignInApi.getSignInResultFromIntent(data);

Auth.GoogleSignInApi.getSignInResultFromIntent(data);

成功:该应用正在请求权限.

is successful: the app is asking for the permission.

我做错了什么?

尽管Google手册中有使用此方法的示例,但为什么requestServerAuthCode会导致DEVELOPER_ERROR:

Why requestServerAuthCode causes DEVELOPER_ERROR, despite there is an example of using this method in Google's manual:

https://developers.google.com/身份/登录/android/offline-access#enable_server-side_api_access_for_your_app

是否有示例如何在Android应用中使用People API?

Is there any sample how to use People API in Android app?

推荐答案

google登录:-

google sign in:-

     GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .build();

GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso); 

在您的btn上,单击调用此方法:-

on your btn click call this method:-

private void signIn() {
        progressDialog(this, "Please wait...", true);
        Intent signInIntent = mGoogleSignInClient.getSignInIntent();
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }

onActivityResult:-

onActivityResult:-

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        progressDialog(this, "Please wait...", false);
        if (requestCode == RC_SIGN_IN) {

            try {
                // Google Sign In was successful, authenticate with Firebase
                Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
                handleSignInResult(task);
            } catch (Exception e) {
                // Google Sign In failed, update UI appropriately
                Log.w(TAG, "Google sign in failed", e);
                // ...
            }
        }
    }

最后保存您的细节:-

private void handleSignInResult(Task<GoogleSignInAccount> task) {
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            socialId = account.getId();
            socialName = account.getDisplayName();
            socialEmail = account.getEmail();
            //you have got all the details now you can go your next screen
        } catch (ApiException e) {
            Toast.makeText(this, "Authentication failed", Toast.LENGTH_SHORT).show();
        }
        mGoogleSignInClient.signOut();
    } 

这篇关于请求服务器身份验证代码时,GoogleSignInResult在Android应用中返回DEVELOPER_ERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆