in recaptcha/src/get_key.php [38:65]
function get_key(string $projectId, string $keyId): void
{
$client = new RecaptchaEnterpriseServiceClient();
$formattedKeyName = $client->keyName($projectId, $keyId);
try {
// Returns a 'Google\Cloud\RecaptchaEnterprise\V1\Key' object
$getKeyRequest = (new GetKeyRequest())
->setName($formattedKeyName);
$key = $client->getKey($getKeyRequest);
$webSettings = $key->getWebSettings();
print('Key fetched' . PHP_EOL);
printf('Display name: %s' . PHP_EOL, $key->getDisplayName());
// $key->getCreateTime() returns a Google\Protobuf\Timestamp object
printf('Create time: %d' . PHP_EOL, $key->getCreateTime()->getSeconds());
printf('Web platform settings: %s' . PHP_EOL, $key->hasWebSettings() ? 'Yes' : 'No');
printf('Allowed all domains: %s' . PHP_EOL, $key->hasWebSettings() && $webSettings->getAllowAllDomains() ? 'Yes' : 'No');
printf('Integration Type: %s' . PHP_EOL, $key->hasWebSettings() ? IntegrationType::name($webSettings->getIntegrationType()) : 'N/A');
} catch (ApiException $e) {
if ($e->getStatus() === 'NOT_FOUND') {
printf('The key with Key ID: %s doesn\'t exist.' . PHP_EOL, $keyId);
} else {
print('getKey() call failed with the following error: ');
print($e);
}
}
}