php - 如何在 PHP 应用程序中验证 Google Cloud Speech-To-Text 客户端?

标签 php google-authentication google-speech-api google-speech-to-text-api

对于 PHP 应用程序中的 Cloud Speech-To-Text 客户端身份验证,我使用以下内容:

 $credentials = 'C:\cred.json';
 $client=new SpeechClient(['credentials'=>json_decode(file_get_contents($credentials), true)]);

由于某些原因我收到错误:

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST https://oauth2.googleapis.com/token resulted in a 400 Bad Request response: {"error":"invalid_scope","error_description":"Invalid OAuth scope or ID token audience provided."}

上述身份验证方法在 Text-To-Speech API 中完美运行。

$credentials = 'C:\cred.json';
$client = new TextToSpeechClient(['credentials' => json_decode(file_get_contents($credentials), true)]);

有什么问题/缺失?

最佳答案

通过更新 Auth 模块(在 Vendor 文件夹中)解决了这个问题。只需将您的 Auth 版本更改为您的 composer.json 文件中的最新版本即可。

{
    "require": {
        "google/auth": "1.14.3",
        "google/cloud-text-to-speech": "^0.5.0",
        "google/cloud-speech": "^1.3",
        "google/protobuf": "^3.14",
        "phpmailer/phpmailer": "^6.1",
        "google/apiclient": "2.5"
    }
}

一旦完成,我就跑

composer update

在适当目录中的命令行中。现在可以了。

关于php - 如何在 PHP 应用程序中验证 Google Cloud Speech-To-Text 客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65191899/

相关文章:

php - 是否可以在服务器范围内定义 PHP 类?

php - 多个文件上传问题(简单的php/html)

php - 使用 jquery 和 php 的实时通知

c# - 序列包含多个元素 Microsoft.Owin.Security.AuthenticationManager

node.js - 当 Passportjs 上使用 Google Auth 时,自定义回调从未被调用

android - Google play服务认证(oauth 2.0)

javascript - 如何在 WordPress 插件中使用 Ajax?

google-speech-api - 错误: 14 UNAVAILABLE: Connect Failed with Google Speech API

asp.net-core - Google 语音流 api 的 Grpc 代理服务器没有响应 ( Grpc.Core.RpcException )

google-cloud-platform - SpeechContext 没有 "boost"字段