亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不能把它扔到谷歌reCAPTCHA中的執行者

不能把它扔到谷歌reCAPTCHA中的執行者

慕田峪9158850 2022-08-03 12:59:24
我有一個問題與谷歌驗證碼。我正在使用他們 https://developer.android.com/training/safetynet/recaptcha#java 的例子,但是當我嘗試轉換到.thisExecutor我得到的錯誤是:。com.johny.Aktivity.Activity cannot be cast to java.util.concurrent.Executor我嘗試了 impating,但后來 Android Studio 迫使我包含和 recapcha 總是在那里結束,而不是在 or 中。Executorexecute(Runnable)onSuccess()onFailure()
查看完整描述

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());

                    }

                }

            });


查看完整回答
反對 回復 2022-08-03
  • 1 回答
  • 0 關注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號