【问题标题】:Errors when using the Google Translate API使用 Google Translate API 时出错
【发布时间】:2018-12-04 06:26:46
【问题描述】:

我刚刚开始学习 Google Translate API,并试图弄清楚如何正确设置它。

首先我去了https://console.developers.google.com,在那里我设置了账单,创建了一个项目,进入“凭据”并生成了一个 API 密钥。

然后我转到命令提示符并按照此处描述的步骤通过 composer 安装。我不得不使用composer require google/cloud,因为composer require google/cloud-translation 出错了。

这安装得很好,我现在可以看到目录C:\wamp64\www\myproject\vendor\google\cloud\Translate

然后我尝试像这样创建一个简单的脚本:

<?php

require 'vendor/autoload.php';
use Google\Cloud\Translate\TranslateClient;
$translate = new TranslateClient([
    'key' => '{my API key}'
]);

if(isset($_POST["string"])){
    $string = $_POST["string"];
    $result = $translate->translate($string, [
        'target' => 'fr'
    ]);
    echo $result['text'] . "\n";
}

?>

<html>
<head>
</head>
<body>
<form action="test_translate.php" method="POST">
<input type="text" name="string">
<input type="submit">
</form>
</body>
</html>

但我收到以下错误消息:

( ! ) Fatal error: Uncaught exception 'Google\Cloud\Core\Exception\ServiceException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in C:\wamp64\www\Lifting365\vendor\google\cloud\Core\src\RequestWrapper.php on line 263
( ! ) Google\Cloud\Core\Exception\ServiceException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in C:\wamp64\www\Lifting365\vendor\google\cloud\Core\src\RequestWrapper.php on line 263
Call Stack
#   Time    Memory  Function    Location
1   0.0007  242936  {main}( )   ...\test_translate.php:0
2   0.0489  1920632 Google\Cloud\Translate\TranslateClient->translate( )    ...\test_translate.php:13
3   0.0489  1921032 Google\Cloud\Translate\TranslateClient->translateBatch( )   ...\TranslateClient.php:181
4   0.0489  1921536 Google\Cloud\Translate\Connection\Rest->listTranslations( ) ...\TranslateClient.php:246
5   0.0489  1921848 Google\Cloud\Translate\Connection\Rest->send( ) ...\Rest.php:78
6   0.1728  2338192 Google\Cloud\Core\RequestWrapper->send( )   ...\RestTrait.php:96

我是新手,所以我不确定我是否做对了,或者我是否遗漏了什么。

【问题讨论】:

    标签: php google-translate google-translation-api


    【解决方案1】:

    所以我知道这是显而易见的事情......

    错误声明:SSL certificate problem

    我的目录是:C:\wamp64\www\myproject

    我的网站在 WAMP 上有一个 Alpha 版本,它没有 SSL 证书,然后是一个 Beta 版本和一个实时版本,它们都有证书。

    Google 需要 SSL 证书,因此该脚本可以在我的 beta 子目录中运行,但不能在 WAMP 本地运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-11
      • 2014-01-31
      • 2019-10-19
      • 2017-03-27
      • 1970-01-01
      • 2022-08-04
      • 2023-04-02
      相关资源
      最近更新 更多