亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

谷歌云翻譯:神秘錯誤 400 無效值

谷歌云翻譯:神秘錯誤 400 無效值

PHP
慕婉清6462132 2022-07-02 15:54:27
我正在使用谷歌翻譯(基本版)來翻譯一些字符串。幾分鐘前它工作正常,但現在它只返回錯誤 400。代碼非常簡單:function translatePhrase($text, $target, $source = 'it') {    $sourceLanguage = $source;    $targetLanguage = $target;     $translate = new TranslateClient();    $result = $translate->translate($text, [        'source' => $sourceLanguage,        'target' => $targetLanguage,    ]);    $output = $result['text'];    return $output;}它返回:Uncaught Google\Cloud\Core\Exception\BadRequestException: {"error": {"code": 400,"message": "Invalid Value","errors": [{"message": "Invalid Value","domain": "global","reason": "invalid"}]}}in \vendor\google\cloud-core\src\RequestWrapper.php:362Stack trace:#0 \vendor\google\cloud-core\src\RequestWrapper.php(206): Google\Cloud\Core\RequestWrapper->convertToGoogleException(Object(GuzzleHttp\Exception\ClientException))#1 \translate\vendor\google\cloud-core\src\RestTrait.php(95): Google\Cloud\Core\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array)#2 \translate\vendor\google\cloud-translate\src\V2\Connection\Rest.php(83): Google\Cloud\Translate\V2\Connection\Rest->send('translations', 'translate', Array)#3 \translate\vendor\google\cloud-translate\src\V2\TranslateClient.php(248): Google\Cloud\Translate\V2\Connection\Rest->listTrain [\translate\vendor\google\cloud-core\src\RequestWrapper.php riga 362]有什么想法嗎 ?
查看完整描述

2 回答

?
德瑪西亞99

TA貢獻1770條經驗 獲得超3個贊

我明白了原因。

基本上,我是在強制使用錯誤的源語言。當我指定正確的源語言時,它再次起作用。


查看完整回答
反對 回復 2022-07-02
?
侃侃無極

TA貢獻2051條經驗 獲得超10個贊

正如人們所看到的,它恰好在這里出錯了......所以選項數組有問題。它應該看起來像這樣(因為沒有單個示例傳遞source語言代碼,而是$result['source']返回自動檢測):


function translatePhrase($text, $target) {

    $translate = new TranslateClient();

    $result = $translate->translate($text, [

        'target' => $target

    ]);

    return $result['text'];

}


查看完整回答
反對 回復 2022-07-02
  • 2 回答
  • 0 關注
  • 345 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號