評価へのアノテーション付け

評価にアノテーションを付けて reCAPTCHA Enterprise による分析の正確性に関するフィードバックを提供します。

コードサンプル

Java

reCAPTCHA Enterprise への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。


import com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient;
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;

public class AnnotateAssessment {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectID = "project-id";
    String assessmentId = "assessment-id";
    annotateAssessment(projectID, assessmentId);
  }

  /**
   * Pre-requisite: Create an assessment before annotating.
   *
   * <p>Annotate an assessment to provide feedback on the correctness of recaptcha prediction.
   *
   * @param projectID: GCloud Project id
   * @param assessmentId: Value of the 'name' field returned from the CreateAssessment call.
   */
  public static void annotateAssessment(String projectID, String assessmentId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `client.close()` method on the client to safely
    // clean up any remaining background resources.
    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.FRAUDULENT)
              .addReasons(Reason.FAILED_TWO_FACTOR)
              .build();

      // Empty response is sent back.
      AnnotateAssessmentResponse response = client.annotateAssessment(annotateAssessmentRequest);
      System.out.println("Annotated response sent successfully ! " + response);
    }
  }
}

Python

reCAPTCHA Enterprise への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。

from google.cloud import recaptchaenterprise_v1

def annotate_assessment(project_id: str, assessment_id: str) -> None:
    """Pre-requisite: Create an assessment before annotating.
        Annotate an assessment to provide feedback on the correctness of recaptcha prediction.
    Args:
        project_id: Google Cloud Project ID
        assessment_id: Value of the 'name' field returned from the create_assessment() call.
    """

    client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient()

    assessment_name = f"projects/{project_id}/assessments/{assessment_id}"
    # 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
    request = recaptchaenterprise_v1.AnnotateAssessmentRequest()
    request.name = assessment_name
    request.annotation = request.Annotation.FRAUDULENT
    request.reasons = [request.Reason.FAILED_TWO_FACTOR]

    # Empty response is sent back.
    client.annotate_assessment(request)
    print("Annotated response sent successfully ! ")

次のステップ

他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。