How to do one tap signin and signup in Android

Viewed 1146

Here is my code which I followed from Google Developers page

signInRequest = BeginSignInRequest.builder()
    .setPasswordRequestOptions(BeginSignInRequest.PasswordRequestOptions.builder()
        .setSupported(true)
        .build())
    .setGoogleIdTokenRequestOptions(BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
        .setSupported(true)
        // Your server's client ID, not your Android client ID.
        .setServerClientId(getString(R.string.server_id))
        // Only show accounts previously used to sign in.
        .setFilterByAuthorizedAccounts(true)
        .build())
    .build();

oneTapClient.beginSignIn(signInRequest)
    .addOnSuccessListener(this, new OnSuccessListener<BeginSignInResult>() {
        @Override
        public void onSuccess(BeginSignInResult result) {
            try {
                startIntentSenderForResult(
                    result.getPendingIntent().getIntentSender(), REQ_ONE_TAP, null, 0, 0, 0);
            } catch (IntentSender.SendIntentException e) {
                Log.e(TAG, "Couldn't start One Tap UI: " + e.getLocalizedMessage());
            }
        }
    })
    .addOnFailureListener(this, new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            // No saved credentials found. Launch the One Tap sign-up flow, or
            // do nothing and continue presenting the signed-out UI.
            Log.d(TAG, e.getLocalizedMessage());
        }
    });

I am implementing one tap signin and signup in my Android application and also I have created a project in Google API console and mentioned the client ID here but the above code is not working.

I have searched example projects but not available and also an example YouTube video for step by step code flow is not available. What can I try next?

1 Answers

The log would have helped, although I am guessing this is the Exception:

No matching credentials found

In the code change

.setFilterByAuthorizedAccounts(true)

to

.setFilterByAuthorizedAccounts(false)
Related