迁移到 v1 API

本文档介绍了如何从 v1beta1 版本迁移到 v1 reCAPTCHA Enterprise API 版本。

如果您使用 v1beta1 创建评估并为其添加注释,我们建议您 使用 v1,因为 reCAPTCHA 等新功能 账号卫士,仅适用于 v1v1 同时支持 API 密钥和服务账号身份验证。

如需将评估调用从 v1beta1 迁移到 v1,请执行以下操作:

  1. 替换了用于创建评估的调用。

    替换 https://recaptchaenterprise.googleapis.com/v1beta1/projects/PROJECT_ID/assessments?key=API_KEYhttps://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/assessments?key=API_KEY

  2. 了解评估的 JSON 响应中的变化:

    当您使用 v1 时,reasonsscore 字段封装在 riskAnalysis,当您使用 v1beta1 时,reasonsscore 字段未封装在响应中。

    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)
    }
    }

  3. 更新您的环境,以使用 v1 的 JSON 响应中的 reasonsscore 字段。

    以下示例代码展示了 v1v1beta1 响应中使用的字段:

    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)
    )
    ....
    ....
  4. 替换对评估进行注释的调用。

    https://recaptchaenterprise.googleapis.com/v1beta1/projects/PROJECT_ID/assessments}:annotate 替换为 https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/assessments}:annotate

  5. 如果您目前使用审核日志记录功能记录 createannotate API 调用,建议您改用平台日志记录(仅适用于 v1)。

后续步骤