Google Speech API返回PERMISSION_DENIED,无法使用客户端项目识别请求

时间:2017-01-09 07:53:21

标签: java google-cloud-platform google-cloud-speech

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

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

1 个答案:

答案 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。

我希望它有所帮助。