3

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

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

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

致命错误:未捕获的 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)]);

有什么问题/遗漏?

4

2 回答 2

5

通过更新 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"
    }
}

一旦完成,我就跑

作曲家更新

在适当目录中的命令行中。现在它起作用了。

于 2020-12-19T01:38:51.120 回答
1

我想在评论中概述@KevinDriessen的建议,因为在不全面更新供应商目录的情况下解决问题(我遇到了同样的问题),这并不总是可取的。

composer update google/cloud-text-to-speech --with-dependencies
于 2021-02-27T07:59:31.827 回答