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

Uvo*_*ech 3 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)]);
Run Code Online (Sandbox Code Playgroud)

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

致命错误:未捕获的 GuzzleHttp\Exception\ClientException:客户端错误:POST https://oauth2.googleapis.com/token导致400 Bad Request响应:{"error":"invalid_scope","error_description":"提供的 OAuth 范围或 ID 令牌受众无效。"}

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

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

有什么问题/缺失?

Uvo*_*ech 5

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

{
    "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"
    }
}
Run Code Online (Sandbox Code Playgroud)

一旦完成,我就跑

作曲家更新

在相应目录中的命令行中。现在它起作用了。

  • 这救了我的命!我宁愿不向我的作曲家添加子依赖项或运行“作曲家更新”,这也会更新所有其他库。运行 `composer update google/cloud-text-to-speech --with-dependencies` 也工作得很好。或者,您可以运行 `composer show` 并检查您可能需要更新哪些依赖项(在我的例子中,如果我更新了“google/auth”、“google/gax”和“google/cloud-core”,它就会起作用) (2认同)