Skip to content

Commit 1289fa6

Browse files
authored
refactor: avoid ApiKeyOption in sample (#14760)
1 parent 3601f91 commit 1289fa6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/api_key.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// [START apikeys_authenticate_api_key]
2323
#include "google/cloud/language/v1/language_client.h"
2424
#include "google/cloud/common_options.h"
25+
#include "google/cloud/grpc_options.h"
2526
#include "google/cloud/options.h"
2627

2728
// [END apikeys_authenticate_api_key]
@@ -82,7 +83,10 @@ void AuthenticateWithApiKey(std::vector<std::string> const& argv) {
8283
"authenticate-with-api-key <project-id> <api-key>"};
8384
}
8485
namespace gc = ::google::cloud;
85-
auto options = gc::Options{}.set<gc::ApiKeyOption>(argv[1]);
86+
auto options =
87+
gc::Options{}
88+
.set<gc::GrpcCredentialOption>(grpc::SslCredentials({}))
89+
.set<gc::CustomHeadersOption>({{"x-goog-api-key", argv[1]}});
8690
auto client = gc::language_v1::LanguageServiceClient(
8791
gc::language_v1::MakeLanguageServiceConnection(options));
8892

@@ -150,6 +154,7 @@ void AutoRun(std::vector<std::string> const& argv) {
150154

151155
try {
152156
AuthenticateWithApiKey({project_id, key.key_string()});
157+
break;
153158
} catch (gc::Status const& s) {
154159
if (backoff == 0) throw(s);
155160
std::cout << "Sleeping for " << backoff << " seconds\n";

0 commit comments

Comments
 (0)