GoogleSignInResult returns DEVELOPER_ERROR in android app when requesting server authorization code

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

The following code is used to log 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 code:

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

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

      

I am getting DEVELOPER_ERROR result.

The app is signed with a SHA1 fingerprint I configure in the developer console.

The OAUTH client id is taken from my application's "web client" JSON configuration.

All APIs are included in the google developer console.

If I remove the .requestServerAuthCode () method:

    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();

      

Result

Auth.GoogleSignInApi.getSignInResultFromIntent (data);

successful: the application requests permission.

What am I doing wrong?

Why is requestServerAuthCode calling DEVELOPER_ERROR, even though Google manual has an example using this method:

https://developers.google.com/identity/sign-in/android/offline-access#enable_server-side_api_access_for_your_app

Is there an example of using the People API in an Android app?

+4


source to share


2 answers


Instead of passing your production / debug client_id to

.requestServerAuthCode ()



use the web client_id instead - I think the google login will always use the server_client_id from string.xml.

Technically, you need to use both keys.

0


source


Login to Google: -

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

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

      

on your click call this method: -

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

      



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);
                // ...
            }
        }
    }

      

finally save your data: -

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();
    } 

      

0


source







All Articles