gpt4 book ai didi

java - 无法在 google reCAPTCHA 中将其转换为 Executor

转载 作者:行者123 更新时间:2023-11-29 23:17:24 27 4
gpt4 key购买 nike

我在使用 google recaptcha 时遇到问题。我正在使用他们来自 https://developer.android.com/training/safetynet/recaptcha#java 的示例但是当我尝试将 this 转换为 Executor 时出现错误。

我得到的错误是:com.johny.Aktivity.Activity cannot be cast to java.util.concurrent.Executor

我尝试实现 Executor 但随后 Android Studio 强制我包含 execute(Runnable) 并且 recapcha 总是在那里结束而不是在 onSuccess()onFailure()

最佳答案

实际上,我不确定为什么 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());
}
}
});

关于java - 无法在 google reCAPTCHA 中将其转换为 Executor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55088899/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com