amp-html - 在 reCAPTCHA 脚本上运行 execute() 时出错
问题描述
Form submission failed: Error: There was an error running execute() on the reCAPTCHA script.
错误图片
当我尝试发送带有 amp-recaptcha 的 amp 表单时,我收到此错误。我生成了不同的密钥,都启用了“允许此密钥与 AMP 页面一起使用”。
你知道有什么问题吗?谢谢。
<form id="amp-recaptcha-input-form" method="POST" action-xhr="https://example.com/api/push" target="_top">
<fieldset>
<label>
<span>Search for</span>
<input type="search" name="term" required>
</label>
<input name="submit-button" type="submit" value="Search">
<amp-recaptcha-input layout="nodisplay" name="recaptcha_token"
data-sitekey="6LcovLIUAAAAAEfNnsbk69bEKH6LvBM2_2rAxmoj" data-action="recaptcha_example">
</amp-recaptcha-input>
</fieldset>
<div class="loading-message">
Loading...
</div>
<div submit-success>
<template type="amp-mustache">
<h1>You searched for: {{term}}</h1>
<div><b>Score:</b> {{score}}</div>
<div><b>Recaptcha token:</b> {{recaptcha_token}}</div>
<div><b>Action:</b> {{action}}</div>
</template>
</div>
<div submit-error>
<template type="amp-mustache">
<h1>Error! Please check the JS Console in your dev tools.</h1>
<p>{{message}}</p>
</template>
</div></form>
解决方案
我也在我的 AMP 页面上实施 reCAPTCHA。首先,您需要以 ( amp-recaptcha-input ) 形式使用 AMP reCAPTCHA 输入组件。在此之后,您需要以与 reCAPTCHA v2 相同的方式验证为 reCAPTCHA v3 生成的令牌。也就是说,在后面的代码中使用 API 请求(post 方法)到https://www.google.com/recaptcha/api/siteverify - 通过发送密钥、令牌和用户 IP 地址(可选)。您将获得一个 JSON 响应,您可以在将表单数据实际提交到您的数据库或电子邮件代码之前对其进行解析和验证。
参考:
推荐阅读
- django - 如何在 django 中使用视频?
- python - 确定每天的员工级别
- excel - IE 11 和 Office 365 - 让 Excel 打开而不是提示
- python - 如何提取字符串的10个字符之前和之后
- ruby-on-rails - 将模型添加到连接表并从 rails 中的不同模型调用它
- java - 大小为 N 的 java Array
- database-design - aws dynamodb 中的参照完整性管理
- r - 我可以让 mailR 或 RDCOMClient 与 R 3.6.3 一起使用吗?
- ios - 第二次 API 调用后应用程序崩溃 (Swift)
- python - 如何确定嵌套列表中的所有元素是否都是唯一的?