Skip to content

Instantly share code, notes, and snippets.

@anehkumar
Created October 9, 2019 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anehkumar/dec49c972999fd8e891d408c38a6b532 to your computer and use it in GitHub Desktop.
Save anehkumar/dec49c972999fd8e891d408c38a6b532 to your computer and use it in GitHub Desktop.
SafetyNet.getClient(MainActivity.this).verifyWithRecaptcha(SITE_KEY)
.addOnSuccessListener(MainActivity.this,
new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {
@Override
public void onSuccess(SafetyNetApi.RecaptchaTokenResponse response) {
// Indicates communication with reCAPTCHA service was
// successful.
String userResponseToken = response.getTokenResult();
Log.e("response", userResponseToken);
if (!userResponseToken.isEmpty()) {
// Validate the user response token using the
// reCAPTCHA siteverify API.
}
}
})
.addOnFailureListener(MainActivity.this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if (e instanceof ApiException) {
// An error occurred when communicating with the
// reCAPTCHA service. Refer to the status code to
// handle the error appropriately.
ApiException apiException = (ApiException) e;
int statusCode = apiException.getStatusCode();
Log.e(TAG, "Error: " + CommonStatusCodes
.getStatusCodeString(statusCode));
} else {
// A different, unknown type of error occurred.
Log.e(TAG, "Error: " + e.getMessage());
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment