本文档介绍了如何从 v1beta1
版迁移到 v1
版 reCAPTCHA Enterprise API。
如果您使用 v1beta1
创建和注释评估,我们建议您改用 v1
,因为 reCAPTCHA 账号防护等新功能仅适用于 v1
。v1
同时支持 API 密钥和服务账号身份验证。
如需将评估调用从 v1beta1
迁移到 v1
,请执行以下操作:
替换了用于创建评估的调用。
将
https://recaptchaenterprise.googleapis.com/v1beta1/projects/PROJECT_ID/assessments?key=API_KEY
替换为https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/assessments?key=API_KEY
了解评估的 JSON 响应中的变化:
使用
v1
时,reasons
和score
字段会封装在响应的riskAnalysis
中;使用v1beta1
时,reasons
和score
字段不会封装在响应中。v1
{ "event":{ "expectedAction":"EXPECTED_ACTION", "hashedAccountId":"ACCOUNT_ID", "siteKey":"KEY_ID", "token":"TOKEN", "userAgent":"(USER-PROVIDED STRING)", "userIpAddress":"USER_PROVIDED_IP_ADDRESS" }, "name":"ASSESSMENT_ID", "riskAnalysis":{ "reasons":[], "score":"SCORE }, "tokenProperties":{ "action":"USER_INTERACTION", "createTime":"TIMESTAMP", "hostname":"HOSTNAME", "invalidReason":"(ENUM)", "valid":(BOOLEAN) } }
v1beta1
{ "event":{ "expectedAction":"EXPECTED_ACTION", "hashedAccountId":"ACCOUNT_ID", "siteKey":"KEY_ID", "token":"TOKEN", "userAgent":"(USER-PROVIDED STRING)", "userIpAddress":"USER_PROVIDED_IP_ADDRESS" }, "name":"ASSESSMENT_ID", "reasons":[], "score":"SCORE", "tokenProperties":{ "action":"USER_INTERACTION", "createTime":"TIMESTAMP", "hostname":"HOSTNAME", "invalidReason":"(ENUM)", "valid":(BOOLEAN) } }
更新您的环境,以使用
v1
的 JSON 响应中的reasons
和score
字段。以下示例代码展示了
v1
和v1beta1
响应中使用的字段:v1
..... ..... # Get the risk score and the reason(s) for reason in response.risk_analysis.reasons: print(reason) print( "The reCAPTCHA score for this token is: " + str(response.risk_analysis.score) ) .... ....
v1beta1
..... ..... # Get the risk score and the reason(s) for reason in response.reasons: print(reason) print( "The reCAPTCHA score for this token is: " + str(response.score) ) .... ....
替换了用于为评估添加注释的调用。
将
https://recaptchaenterprise.googleapis.com/v1beta1/projects/PROJECT_ID/assessments}:annotate
替换为https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/assessments}:annotate
如果您目前使用审核日志记录功能记录
create
和annotate
API 调用,建议您改用平台日志记录(仅适用于v1
)。