【问题标题】:Google reCAPTCHA ERROR for site owner: Invalid site key网站所有者的 Google reCAPTCHA 错误:网站密钥无效
【发布时间】:2020-09-16 21:04:33
【问题描述】:

我无法在我的网站上运行 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 Checkbox,同样的事情发生了。虽然,“站点所有者的错误:无效的站点密钥”现在位于左上方:

    <!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】:

    我已经尝试过您提到的 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).

    【讨论】:

    • 谢谢,@KushalSeth,我的本地主机现在在左下角显示“受 reCAPTCHA 保护”。
    猜你喜欢
    • 1970-01-01
    • 2019-07-28
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 2018-05-04
    • 2015-08-24
    • 1970-01-01
    相关资源
    最近更新 更多