Created
October 9, 2019 10:05
-
-
Save anehkumar/dec49c972999fd8e891d408c38a6b532 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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