Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API key #7347

Open
jonhassall opened this issue May 24, 2024 · 1 comment
Open

API key #7347

jonhassall opened this issue May 24, 2024 · 1 comment
Assignees

Comments

@jonhassall
Copy link

Please improve your documentation on using an API key with your library.

@bshaffer
Copy link
Contributor

Hi @jonhassall, this is a great request. The API key docs are hard to find because not every API supports them. For the APIs which ARE supported, here's how you could take advantage of them:

use Google\Cloud\RecaptchaEnterprise\V1\Client\RecaptchaEnterpriseServiceClient;
use Google\Cloud\RecaptchaEnterprise\V1\ListKeysRequest;
use Google\ApiCore\InsecureCredentialsWrapper;

// Create a client.
$recaptcha = new RecaptchaEnterpriseServiceClient([
    // STEP 1: use insecure credentials wrapper to bypass application default creds
    'credentials' => new InsecureCredentialsWrapper(),
]);

// Prepare the request message.
$formattedParent = RecaptchaEnterpriseServiceClient::projectName('[PROJECT]');
$request = (new ListKeysRequest())->setParent($formattedParent);

// Call the API and handle any network failures.

/** @var PagedListResponse $response */
$response = $recaptchaEnterpriseServiceClient->listKeys($request, [
    // STEP 2: Pass in the API key with each RPC call as a "Call Option"
    'headers' => ['x-goog-api-key' => ['[API-KEY]']],
]);

@bshaffer bshaffer self-assigned this Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants