所以我修改了Google Speech API
示例代码(之前没有工作)与他们的更新通知(关于ClientAuthenticator
中的弃用)相同并得到与以前相同的错误没有解决方案,主机为speech.googleapis.com/v1beta1/speech:asyncrecognize?key=My_Key
我的代码如下:
public static ManagedChannel createChannel(String host) throws IOException {
FileInputStream filestream = new FileInputStream("/home/admin/creds.json");
GoogleCredentials creds = GoogleCredentials.fromStream(filestream).createScoped(OAUTH2_SCOPES);
ManagedChannel channel = ManagedChannelBuilder.forTarget(host).build();
GreeterGrpc.GreeterStub stub = GreeterGrpc.newStub(channel);
stub = stub.withCallCredentials(MoreCallCredentials.from(creds));
System.out.println(channel.authority()+creds);
filestream.close();
return channel;
}
但它只返回一个
WARNING: RPC failed: Status{code=PERMISSION_DENIED, description=The request cannot be identified with a client project. Please pass a valid API key with the request., cause=null}
欢迎任何帮助或建议,谢谢!
答案 0 :(得分:0)
嘿,而不是这样做,
GreeterGrpc.GreeterStub stub = GreeterGrpc.newStub(channel); stub = stub.withCallCredentials(MoreCallCredentials.from(creds));
请执行以下操作:
GreeterGrpc.GreeterStub stub = GreeterGrpc.newStub(channel).withCallCredentials(MoreCallCredentials.from(creds));
当您的代码重新启动存根对象时,您将获得PERMISSION_DENIED。
我希望它有所帮助。