Search in sources :

Example 6 with GetKeyRequest

use of com.google.recaptchaenterprise.v1.GetKeyRequest in project java-recaptchaenterprise by googleapis.

the class GetSiteKey method getSiteKey.

/**
 * Get the reCAPTCHA site key present under the project ID.
 *
 * @param projectID: GCloud Project ID.
 * @param recaptchaSiteKey: Specify the site key to get the details.
 */
public static void getSiteKey(String projectID, String recaptchaSiteKey) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
        // Construct the "GetSiteKey" request.
        GetKeyRequest getKeyRequest = GetKeyRequest.newBuilder().setName(KeyName.of(projectID, recaptchaSiteKey).toString()).build();
        // Wait for the operation to complete.
        ApiFuture<Key> futureCall = client.getKeyCallable().futureCall(getKeyRequest);
        Key key = futureCall.get(5, TimeUnit.SECONDS);
        System.out.println("Successfully obtained the key !" + key.getName());
    }
}
Also used : GetKeyRequest(com.google.recaptchaenterprise.v1.GetKeyRequest) Key(com.google.recaptchaenterprise.v1.Key) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Aggregations

GetKeyRequest (com.google.recaptchaenterprise.v1.GetKeyRequest)4 Test (org.junit.Test)4 Key (com.google.recaptchaenterprise.v1.Key)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 RecaptchaEnterpriseServiceClient (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 GetKeyRequest (com.google.recaptchaenterprise.v1beta1.GetKeyRequest)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 UpdateKeyRequest (com.google.recaptchaenterprise.v1.UpdateKeyRequest)1 Key (com.google.recaptchaenterprise.v1beta1.Key)1 HashMap (java.util.HashMap)1