Using google translate API with cURL

左心房为你撑大大i 提交于 2019-12-11 00:59:10

问题


I'm trying to use the Google Translate API to translate text input by the user on my php based website. So far I have:

<?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);
?>

This isn't returning anything and I don't know what's wrong. I know that the API is set up correctly as when I enter the url into a browser it returns the following:

{
 "data": {
  "translations": [
   {
    "translatedText": "Apfel"
   }
  ]
 }
}

It must be something to do with my code which I took from this This Site

Any help would be appreciated as I'm completely stumped. Thanks!

EDIT: thanks to a comment I was able to find out that I'm getting the following cURL error:

Curl error: SSL certificate problem: unable to get local issuer certificate

回答1:


Please check this url,Hopeful it will help https://jacerdass.wordpress.com/2013/07/19/using-google-translate-in-php/



来源:https://stackoverflow.com/questions/35013483/using-google-translate-api-with-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!