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());
}));
}
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:
The error that led to trying this solution, which only intermittently showed up was:
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.