[英]Using google translate API with cURL
我正在尝试使用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设置正确,因为当我在浏览器中输入网址时,它将返回以下内容:
{
"data": {
"translations": [
{
"translatedText": "Apfel"
}
]
}
}
这一定与我从本网站获取的代码有关
任何帮助将不胜感激,因为我完全陷入了困境。 谢谢!
编辑:感谢的评论,我能够发现我收到以下cURL错误:
Curl error: SSL certificate problem: unable to get local issuer certificate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.