Annotate assessment with account-related metadata
Stay organized with collections
Save and categorize content based on your preferences.
Annotate assessment with account-related metadata to provide feedback on the accuracy of the reCAPTCHA Enterprise's analysis.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["# Annotate assessment with account-related metadata to provide feedback on the accuracy of the reCAPTCHA Enterprise's analysis.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Detect and prevent account-related fraudulent activities on mobile applications](/recaptcha/docs/account-defender-mobile)\n- [Detect and prevent account-related fraudulent activities on websites](/recaptcha/docs/account-defender)\n\nCode sample\n-----------\n\n### Java\n\n\nTo authenticate to reCAPTCHA, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.cloud.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.html;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString.html;\n import com.google.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest.html;\n import com.google.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest.html.Annotation;\n import com.google.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest.html.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest.Reason.html;\n import com.google.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AnnotateAssessmentResponse.html;\n import com.google.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AssessmentName.html;\n import java.io.IOException;\n import java.security.NoSuchAlgorithmException;\n import java.util.UUID;\n\n public class AnnotateAccountDefenderAssessment {\n\n public static void main(String[] args) throws IOException, NoSuchAlgorithmException {\n // TODO(developer): Replace these variables before running the sample.\n // projectID: GCloud Project id.\n String projectID = \"project-id\";\n\n // assessmentId: Value of the 'name' field returned from the CreateAssessment call.\n String assessmentId = \"account-defender-assessment-id\";\n\n // accountId: Set the accountId corresponding to the assessment id.\n String accountId = \"default\" + UUID.randomUUID().toString().split(\"-\")[0];\n\n annotateAssessment(projectID, assessmentId, accountId);\n }\n\n /**\n * Pre-requisite: Create an assessment before annotating. Annotate an assessment to provide\n * feedback on the correctness of recaptcha prediction.\n */\n public static void annotateAssessment(\n String projectID, String assessmentId, String accountId) throws IOException {\n\n try (https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.html client = https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.html.create()) {\n // Build the annotation request.\n // For more info on when/how to annotate, see:\n // https://cloud.google.com/recaptcha-enterprise/docs/annotate-assessment#when_to_annotate\n https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest.html annotateAssessmentRequest =\n https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest.html.newBuilder()\n .setName(https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AssessmentName.html.of(projectID, assessmentId).toString())\n .setAnnotation(Annotation.LEGITIMATE)\n .addReasons(https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AnnotateAssessmentRequest.Reason.html.PASSED_TWO_FACTOR)\n .setAccountId(accountId)\n .build();\n\n // Empty response is sent back.\n https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.AnnotateAssessmentResponse.html response = client.annotateAssessment(annotateAssessmentRequest);\n System.out.println(\"Annotated response sent successfully ! \" + response);\n }\n }\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=recaptcha_enterprise)."]]