我正在尝试通过gRPC使用Google Phishing Protection API,看起来一切here都是直截了当的,但是与here相比,您可以看到使用REST可以发送请求而无需进行身份验证或其他-这样,您可以将API密钥作为查询参数进行传递。
我测试了REST选项,它对我有用,但是尝试使用gRPC选项时,我在尝试进行身份验证时失败,这是我不想做的。
答案 0 :(得分:0)
谈论gRPC,要求您进行身份验证是可以理解的。配额是必需的
答案 1 :(得分:0)
gRPC中的REST key
查询参数等效于x-goog-api-key
元数据。添加该元数据密钥的API会因语言而异。
将Java与googleapi客户端一起使用(应该使用)时,可以使用:
PhishingProtectionServiceV1Beta1Client.create(
PhishingProtectionServiceV1Beta1Settings.newBuilder()
.setCredentialsProvider(new NoCredentialsProvider())
.setHeaderProvider(PhishingProtectionServiceV1Beta1Settings.defaultApiClientHeaderProviderBuilder()
.setApiClientHeaderKey(yourApiKey)
.build())
.build());
在“普通” grpc中,它看起来更像:
import io.grpc.Metadata;
private static final Metadata.Key<String> API_KEY
= Metadata.Key.of("x-goog-api-key", Metadata.ASCII_STRING_MARSHALLER);
Metadata apiKeyMetadata = new Metadata();
apiKeyMetadata.put(API_KEY, yourApiKey);
stub = stub.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(apiKeyMetadata));