php - Google translate api cUrl not working in a Laravel 5 project -


i getting server response of 0 each time try , fetch response using standard curl functionality within laravel project. has nothing combination think when access way other url works fine... kinda lost...

in controller have function below:

$curl = "https://www.googleapis.com/language/translate/v2?key=my-key&source=en&target=nl&q=hello%20world"; echo $curl; $handle = curl_init($curl); curl_setopt($handle, curlopt_url, $curl); curl_setopt($handle, curlopt_returntransfer, true); $response = curl_exec($handle); $responsedecoded = json_decode($response, true);  $responsecode = curl_getinfo($handle, curlinfo_http_code); if($responsecode != 200) {     echo 'fetching translation failed! server response code:' . $responsecode; } else {     echo 'source: ' . $text . '<br>';     echo $responsedecoded['data']; } curl_close($handle); 

the output 0 , error code 0 (zero)

while when access https://www.googleapis.com/language/translate/v2?key=my-key&source=en&target=nl&q=hello%20world url perfect response "hallo wereld"

using example $curl = http://www.jsontest.com/ output correct.

can see doing wrong here?

stichoza/google-translate-php nice alternative you're trying perform:

use stichoza\googletranslate\translateclient;  $tr = new translateclient('en', 'nl'); dd($tr->getresponse('hello world')); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -