【发布时间】:2016-05-02 23:52:51
【问题描述】:
我正在尝试使用 Google Translate API 来翻译用户在我的基于 php 的网站上输入的文本。到目前为止,我有:
<?php
$google_url = "https://www.googleapis.com/language/translate/v2?key=[API KEY]&q=apple&source=en&target=de";
$handle = curl_init($google_url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
$responseDecoded = json_decode($response, true);
curl_close($handle);
$google_res = $responseDecoded['data']['translations'][0]['translatedText'];
print_r($response);
?>
这没有返回任何东西,我不知道出了什么问题。我知道 API 设置正确,因为当我将 url 输入浏览器时,它会返回以下内容:
{
"data": {
"translations": [
{
"translatedText": "Apfel"
}
]
}
}
这一定与我从 This Site 获取的代码有关
任何帮助将不胜感激,因为我完全被难住了。谢谢!
编辑:感谢评论,我发现我收到了以下 cURL 错误:
Curl error: SSL certificate problem: unable to get local issuer certificate
【问题讨论】:
-
您是否收到任何 cURL 错误?在此处了解有关 cURL 错误的更多信息:php.net/manual/en/function.curl-error.php
-
谢谢!我刚刚发现我在 cURL
Curl error: SSL certificate problem: unable to get local issuer certificate中遇到了这个错误
标签: php json api curl translate