首页 > 解决方案 > recaptcha v3 - 网站所有者的错误:无效的密钥类型

问题描述

我在我的网站上的 Google Recaptcha V3 中收到以下错误。

网站所有者的错误:无效的密钥类型

在此处输入图像描述

我正在使用以下方法来验证验证码:

  1. 添加脚本
<script src="https://www.google.com/recaptcha/api.js?render=API_KEY"></script>
  1. 在提交验证:
$('.submit-e-way-bill-registration').on('submit', function (e) {
    e.preventDefault();
    var self = this;
    if ($(self)[0].checkValidity()) {
        grecaptcha.ready(function () {
            grecaptcha.execute('API_KEY', {
                action: 'homepage'
            }).then(function (token) {
                console.log(token);

                console.log('google captcha initiated');
                $('[name=captcha_token]').val(token);

                var data = $(self).serialize();
                $('.save-button-ewb').prop('disabled', true);
                $.post('/api/submit-e-way-bill-registration.php', data, function (result) {
                    $('.save-button-ewb').prop('disabled', false);
                    console.log('status');
                    if (result.status == 'success') {
                        $('.success-message').show();
                        $('.submit-e-way-bill-registration').hide();
                    } else {
                        $('.error-message').show();
                        $('.submit-e-way-bill-registration').hide();
                    }
                });
            });
        });

    }
});

这曾经以这种方式工作(大约 3-4 个月前)。现在,当我检查时,我收到了上述错误。

谁能告诉我代码有什么问题???

标签: javascripthtmlrecaptcha

解决方案


几天前我遇到了这种错误。我通过生成正确的 ReCaptcha 站点的客户端密钥解决了这个问题。在我看来,您的脚本需要 google ReCaptcha v2,但您使用的是 v3。请检查此屏幕截图。这解决了我的问题。 在此处输入图像描述

如果您在 react 中使用节点模块,请从此文档获取更多详细信息。


推荐阅读