1 回答
TA贡献1735条经验 获得超5个赞
实际上,我不确定为什么在android开发人员网站上显示的代码不起作用,但是您可以尝试下面的代码,其中我只是对成功和失败的侦听器使用了不同的方法。
SafetyNet.getClient(this).verifyWithRecaptcha("YOUR_API_SITE_KEY")
.addOnSuccessListener(new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {
@Override
public void onSuccess(SafetyNetApi.RecaptchaTokenResponse recaptchaTokenResponse) {
// Indicates communication with reCAPTCHA service was
// successful.
String userResponseToken = recaptchaTokenResponse.getTokenResult();
if (!userResponseToken.isEmpty()) {
// Validate the user response token using the
// reCAPTCHA siteverify API.
Log.e(TAG, "VALIDATION STEP NEEDED");
}
}
})
.addOnFailureListener(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());
}
}
});
添加回答
举报