使用与帐号相关的元数据对评估进行注释,以提供有关 reCAPTCHA Enterprise 分析的准确性的反馈。
深入探索
如需查看包含此代码示例的详细文档,请参阅以下内容:
代码示例
Java
import com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient;
import com.google.protobuf.ByteString;
import com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest;
import com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest.Annotation;
import com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest.Reason;
import com.google.recaptchaenterprise.v1.AnnotateAssessmentResponse;
import com.google.recaptchaenterprise.v1.AssessmentName;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
public class AnnotateAccountDefenderAssessment {
public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
// TODO(developer): Replace these variables before running the sample.
// projectID: GCloud Project id.
String projectID = "project-id";
// assessmentId: Value of the 'name' field returned from the CreateAssessment call.
String assessmentId = "account-defender-assessment-id";
// hashedAccountId: Set the hashedAccountId corresponding to the assessment id.
ByteString hashedAccountId = ByteString.copyFrom(new byte[] {});
annotateAssessment(projectID, assessmentId, hashedAccountId);
}
/**
* Pre-requisite: Create an assessment before annotating. Annotate an assessment to provide
* feedback on the correctness of recaptcha prediction.
*/
public static void annotateAssessment(
String projectID, String assessmentId, ByteString hashedAccountId) throws IOException {
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
// Build the annotation request.
// For more info on when/how to annotate, see:
// https://cloud.google.com/recaptcha-enterprise/docs/annotate-assessment#when_to_annotate
AnnotateAssessmentRequest annotateAssessmentRequest =
AnnotateAssessmentRequest.newBuilder()
.setName(AssessmentName.of(projectID, assessmentId).toString())
.setAnnotation(Annotation.LEGITIMATE)
.addReasons(Reason.PASSED_TWO_FACTOR)
.setHashedAccountId(hashedAccountId)
.build();
// Empty response is sent back.
AnnotateAssessmentResponse response = client.annotateAssessment(annotateAssessmentRequest);
System.out.println("Annotated response sent successfully ! " + response);
}
}
}
后续步骤
如需搜索并过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器。