【问题标题】:How to authenticate Google Cloud Speech-To-Text client in PHP application?如何在 PHP 应用程序中验证 Google Cloud Speech-To-Text 客户端?
【发布时间】:2023-04-01 22:44:01
【问题描述】:

对于 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)]);

出了什么问题/遗漏了什么?

【问题讨论】:

  • 我遇到了同样的问题,但在我的情况下是相反的。 Speech-To-Text 就像一个魅力,但 Text-To-Speech 会产生你提到的错误。你解决了吗?

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


【解决方案1】:

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

composer update google/cloud-text-to-speech --with-dependencies

【讨论】:

    【解决方案2】:

    通过更新 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,这也会更新所有其他库。运行composer update google/cloud-text-to-speech --with-dependencies 也可以正常工作。或者,您可以运行 composer show 并检查您可能需要更新哪些依赖项(在我的情况下,如果我更新了“google/auth”、“google/gax”和“google/cloud-core”,它就可以工作)
    猜你喜欢
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 2022-09-26
    • 1970-01-01
    相关资源
    最近更新 更多