简体   繁体   中英

Google Recaptcha Giving INTERNAL_ERROR on Android & IOS

I'm using Google recaptcha api to implement captcha on login action in my app. But every time I try to initialise the recaptcha api to get the recaptcha tasks client then It's giving either INTERNAL_ERROR or Timed out waiting for 10000 ms

I'm calling initiateSDK inside onCreate() of Application activity

Please let me know what's the reason for these errors and solution to fix.

In iOS, we are using same approach.

Code Snippet

public void initiateSDK(Context context) {
        if (recaptchaTasksClient == null) {
            init(context);
        }
    }

private void init(Context context) {
    new Handler().post(() -> Recaptcha.getTasksClient((Application) context.getApplicationContext(), BuildConfig.RECAPTCHA_API_KEY)
        .addOnSuccessListener(client -> {
            recaptchaTasksClient = client;
        })
        .addOnFailureListener(e -> {
            e.printStackTrace();
            Log.d("RECAPTCHA", e.getMessage());
        }));
}

Here are a few things you can try:

Check the version of the reCAPTCHA API that you're using. It's possible that you're using an outdated version, which could cause issues.

Make sure that you've correctly implemented the API on your site. It's possible that there is a problem with the way you've implemented the API, which could be causing the INTERNAL_ERROR message to appear.

Check your site's security settings. It's possible that your site's security settings are preventing the reCAPTCHA API from functioning correctly.

Try clearing your browser's cache and cookies. This can help to resolve issues that are caused by outdated data stored in your browser.

Make sure that you have a valid API key. It's possible that you're using an invalid or outdated API key, which could cause the INTERNAL_ERROR message to appear.

If you've tried these steps and are still experiencing issues with Google reCAPTCHA on Android and iOS, it's possible that the issue could be related to a problem with the API itself. In this case, you may want to try contacting Google for further assistance.

I experienced this. What ended up being the issue was that the client initialization insisted on being done on a UI thread. The working code ended up looking something like this:

private fun initializeRecaptchaClient() {
    lifecycleScope.launch {
      withContext(Dispatchers.Main) {
        Recaptcha.getClient(application, "SITE_KEY")
        .onSuccess {
            this.recaptchaClient = it
          }
          .onFailure {
            Log.e("Error initializing Recaptcha client", it)
          }
      }
    }
  }

The error that led to trying this solution, which only intermittently showed up was:

E/ViewConfiguration: Tried to access UI constants from a non-visual Context:[overridden Application class]@870795fUI constants, such as display metrics or window metrics, must be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen java.lang.IllegalArgumentException: Tried to access UI constants from a non-visual Context:[overridden Application class]@870795f

I'm very much not entirely sure why that is. I did get the client to initialize successfully in a brand new test project without needing to force to the Main thread.

Although another cause of the "Internal Error" that I experienced while trying to get it working in the new app was forgetting the INTE.NET permission.

I hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM