
这允许我限制对我的特定AndroID应用的访问.但是,我一直无法找到如何使用GRPC的API密钥.我目前正在从JsON文件创建一个GoogleCredentials实例,这很好用.如何从API密钥获取凭证对象?
解决方法 您可以使用API密钥尝试此 *** 作final ManagedChannel channel = new OkhttpChannelProvIDer() .builderForAddress(HOSTname,PORT) .nameResolverFactory(new DnsnameResolverProvIDer()) .intercept(new Interceptor(API_KEY)) .build();speechStub = SpeechGrpc.newStub(channel);private static final class Interceptor implements ClIEntInterceptor { private final String APIKey; private static Metadata.Key<String> API_KEY_header = Metadata.Key.of("x-goog-API-key",Metadata.ASCII_STRING_MARSHALLER); public Interceptor(String APIKey) { this.APIKey = APIKey; } @OverrIDe public <ReqT,RespT> ClIEntCall<ReqT,RespT> interceptCall( MethodDescriptor<ReqT,RespT> method,CallOptions callOptions,Channel next) { ClIEntCall<ReqT,RespT> call = next.newCall(method,callOptions); call = new ForwardingClIEntCall.SimpleForwardingClIEntCall<ReqT,RespT>(call) { @OverrIDe public voID start(Listener<RespT> responseListener,Metadata headers) { if (APIKey != null && !APIKey.isEmpty()) { headers.put(API_KEY_header,APIKey); } super.start(responseListener,headers); } }; return call; }} 总结 以上是内存溢出为你收集整理的使用API密钥在Android上通过GRPC验证Google Cloud Speech全部内容,希望文章能够帮你解决使用API密钥在Android上通过GRPC验证Google Cloud Speech所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)