@@ -33,26 +33,40 @@ on authenticating your client. Once authenticated, you'll be ready to start maki
3333``` php
3434require 'vendor/autoload.php';
3535
36+ use Google\ApiCore\ApiException;
37+ use Google\Cloud\RecaptchaEnterprise\V1\Client\RecaptchaEnterpriseServiceClient;
38+ use Google\Cloud\RecaptchaEnterprise\V1\CreateKeyRequest;
3639use Google\Cloud\RecaptchaEnterprise\V1\Key;
37- use Google\Cloud\RecaptchaEnterprise\V1\RecaptchaEnterpriseServiceClient;
3840use Google\Cloud\RecaptchaEnterprise\V1\WebKeySettings;
3941use Google\Cloud\RecaptchaEnterprise\V1\WebKeySettings\IntegrationType;
4042
43+ $formattedParent = RecaptchaEnterpriseServiceClient::projectName('[PROJECT]');
44+ $keyDisplayName = '[DISPLAY_NAME]';
4145
42- $client = new RecaptchaEnterpriseServiceClient();
43- $project = RecaptchaEnterpriseServiceClient::projectName('[MY_PROJECT_ID]');
46+ // Create a client.
47+ $recaptchaEnterpriseServiceClient = new RecaptchaEnterpriseServiceClient();
48+
49+ // Prepare the request message.
4450$webKeySettings = (new WebKeySettings())
4551 ->setAllowedDomains(['example.com'])
4652 ->setAllowAmpTraffic(false)
4753 ->setIntegrationType(IntegrationType::CHECKBOX);
4854$key = (new Key())
4955 ->setWebSettings($webKeySettings)
50- ->setDisplayName('my sample key' )
56+ ->setDisplayName($keyDisplayName )
5157 ->setName('my_key');
52-
53- $response = $client->createKey($project, $key);
54-
55- printf('Created key: %s' . PHP_EOL, $response->getName());
58+ $request = (new CreateKeyRequest())
59+ ->setParent($formattedParent)
60+ ->setKey($key);
61+
62+ // Call the API and handle any network failures.
63+ try {
64+ /** @var Key $response */
65+ $response = $recaptchaEnterpriseServiceClient->createKey($request);
66+ printf('Created key: %s' . PHP_EOL, $response->getName());
67+ } catch (ApiException $ex) {
68+ printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
69+ }
5670```
5771
5872### Debugging
0 commit comments