A
A
Alexander2019-10-01 23:40:52
Java
Alexander, 2019-10-01 23:40:52

Android + Google API OAuth developer registration required?

Introductory:
There is very little experience in development. Implemented work with Google Sheets and Calendar in Java via API. I'm trying to transfer functionality to an Android application.
Problem:
Faced the problem that the implemented authorization is not suitable for Android.
Began to dig the Internet and documentation. Found, like, a ready-made solution. Tried to run.
I get an error: signInResult:failed code=10
The error says:
public static final int DEVELOPER_ERROR
The application is misconfigured. This error is not recoverable and will be treated as fatal. The developer should look at the logs after this to determine more actionable information.
Constant Value: 10

Not very informative. Especially for a newbie
Implementation code:

private static final int RC_SIGN_IN = 9001;
    private GoogleSignInClient mGoogleSignInClient;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.button).setOnClickListener((View.OnClickListener) this);
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        mGoogleSignInClient = GoogleSignIn.getClient(this, gso);


    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                signIn();
                break;
            // ...
        }
    }

    private void signIn() {
        Intent signInIntent = mGoogleSignInClient.getSignInIntent();
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }

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

        // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            // The Task returned from this call is always completed, no need to attach
            // a listener.
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            handleSignInResult(task);
        }
    }

    private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
        try {
            GoogleSignInAccount account = completedTask.getResult(ApiException.class);

            // Signed in successfully, show authenticated UI.
            updateUI(account);
        } catch (ApiException e) {
            // The ApiException status code indicates the detailed failure reason.
            // Please refer to the GoogleSignInStatusCodes class reference for more information.
            Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
            updateUI(null);
        }
    }

    private void updateUI(@Nullable GoogleSignInAccount account) {
        if (account != null) {
            findViewById(R.id.button).setVisibility(View.GONE);
        } else {
            findViewById(R.id.button).setVisibility(View.VISIBLE);
        }
    }

Questions:
1. Is it possible that the error is related to the fact that the token was not created?
2. Do you need a developer certificate to create an authorization token?
3. If the questions above are not related to the error, maybe someone has ready-made solutions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AndroidRS, 2019-10-01
@roro_4x

I dare to suggest that the error may lie in the fact that you did not specify the certificate fingerprint (SHA1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question