0

所以我修改了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}

欢迎任何帮助或建议,谢谢!

4

1 回答 1

0

嘿,而不是这样做,

GreeterGrpc.GreeterStub 存根 = GreeterGrpc.newStub(channel); stub = stub.withCallCredentials(MoreCallCredentials.from(creds));

请执行以下操作:

GreeterGrpc.GreeterStub 存根 = GreeterGrpc.newStub(channel).withCallCredentials(MoreCallCredentials.from(creds));

当您的代码重新启动存根对象时,您将获得 PERMISSION_DENIED。

我希望它有所帮助。

于 2017-03-30T16:36:04.300 回答