网站所有者的Google reCAPTCHA错误:无效的网站密钥

问题描述 投票:2回答:1

我无法在我的网站上使用reCAPTCHA v3。我已经从Google reCAPTCHA v3网站中输入了正确的代码,但是它在右下角显示“网站所有者错误:无效的网站密钥”。

我只有7岁,如果我错过了一些事情,请放轻松

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Recaptcha test</title>
    <script src="https://www.google.com/recaptcha/api.js"></script>
    <script>
      function onSubmit(token) {
          document.getElementById("demo-form").submit();
      }
    </script>
    <script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key"></script>


<body>
<button class="g-recaptcha"
        data-sitekey="reCAPTCHA_site_key"
        data-callback='onSubmit'
        data-action='submit'>Submit</button>
<script>
    function onClick(e) {
        e.preventDefault();
        grecaptcha.ready(function() {
            grecaptcha.execute('reCAPTCHA_site_key', {action: 'submit'}).then(function(token) {
                // Add your logic to submit to your backend server here.
            });
        });
    }
</script>


</head>
</body>
</html>

然后,我尝试了reCAPTCHA v2复选框,发生了同样的事情。虽然,“网站所有者错误:无效的网站密钥”现在位于左上方:

    <!DOCTYPE html>?
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Recaptcha test</title>
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>

    <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
            async defer>
    </script>



<body>
<form action="?" method="POST">
    <div class="g-recaptcha" data-sitekey="your_site_key"></div>
    <br/>
    <input type="submit" value="Submit">
</form>
<script type="text/javascript">
    var onloadCallback = function() {
        alert("grecaptcha is ready!");
    };
</script>



</head>
</body>
</html>
javascript html recaptcha
1个回答
0
投票

我已经尝试过您提到的reCAPTCHA v3代码。

  • reCAPTCHA_site_key位于三个位置,请检查是否在标题"COPY SITE KEY"下用正确的站点密钥替换了它。

  • 原因是显示“网站所有者错误:无效的网站密钥”,原因是您可能正在尝试文件系统访问该密钥。它在文件系统上不起作用,即,这将不起作用:file:///E:/Personal%20Data/stackoverflow/recapcha.html

  • 将您的站点托管在IIS / Node等本地服务器上,并在Recaptcha的域配置中添加相同的域。

    for example if your website is: https://www.testingrecapcha.com/ then add testingrecapcha.com in domains of rechapcha configurations. (to reach admin console of recapcha, use this: https://www.google.com/recaptcha/admin and select your relevant site and click on settings icon).

© www.soinside.com 2019 - 2024. All rights reserved.