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());
}
}
});
添加回答
舉報