本文档介绍了如何从 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
)。