3

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());
        }));
}
ajaymodi
  • 31
  • 5

2 Answers2

1

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.

  • This answer looks like it was generated by an AI (like ChatGPT), not by an actual human being. You should be aware that [posting AI-generated output is officially **BANNED** on Stack Overflow](https://meta.stackoverflow.com/q/421831). If this answer was indeed generated by an AI, then I strongly suggest you delete it before you get yourself into even bigger trouble: **WE TAKE PLAGIARISM SERIOUSLY HERE.** Please read: [Why posting GPT and ChatGPT generated answers is not currently allowed](https://stackoverflow.com/help/gpt-policy). – tchrist Jul 15 '23 at 22:04
0

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 INTERNET permission.

I hope this helps someone.

lashiel
  • 145
  • 2
  • 9