You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用reCAPTCHA Enterprise标注评估接口遇404错误及PHP SDK咨询

reCAPTCHA Enterprise标注接口404问题修复及PHP SDK实现方案

一、404错误原因及修复

你的404问题核心是URL格式错误,官方标注接口的正确路径需要追加:annotate后缀,且请求方法必须为PATCH:

  • 正确请求URL:https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/assessments/ASSESSMENT_ID:annotate
  • 必须使用PATCH请求方法,而非POST/GET
  • 请求体保持{"annotation": "LEGITIMATE"},同时需设置请求头Content-Type: application/json

另外,直接访问https://recaptchaenterprise.googleapis.com返回404是正常的,该域名根路径无服务,所有API请求都需要携带完整的版本号及资源路径。

二、PHP SDK实现标注操作

可以通过Google Cloud PHP SDK实现该功能,步骤如下:

  1. 安装依赖
    在项目根目录执行Composer命令:
composer require google/cloud-recaptcha-enterprise
  1. 编写代码示例
<?php

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\RecaptchaEnterprise\V1\AnnotateAssessmentRequest;
use Google\Cloud\RecaptchaEnterprise\V1\Annotation;
use Google\Cloud\RecaptchaEnterprise\V1\RecaptchaEnterpriseServiceClient;

// 替换为你的项目ID和评估ID
$projectId = 'YOUR_PROJECT_ID';
$assessmentId = 'YOUR_ASSESSMENT_ID';

// 初始化客户端
$client = new RecaptchaEnterpriseServiceClient();

// 构建请求对象
$request = (new AnnotateAssessmentRequest())
    ->setName($client->assessmentName($projectId, $assessmentId))
    ->setAnnotation(Annotation::LEGITIMATE);

// 执行标注请求
$response = $client->annotateAssessment($request);

// 处理响应
printf('标注成功,评估ID:%s' . PHP_EOL, $response->getName());

$client->close();

注意:需确保你的服务账号已拥有recaptchaenterprise.assessments.annotate权限,并且正确配置了认证凭据(可通过环境变量GOOGLE_APPLICATION_CREDENTIALS指定JSON密钥文件路径)。

内容的提问来源于stack exchange,提问作者Whip

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 17:30:00