Reputation: 163
I want to access the Google Translate APIv2. Here is the url:
I already have the key and this url is working fine if I am using it in the browser address bar.
My problem is that I do not know how to call this url using REST. I want to get the result stored in a variable.
Upvotes: 1
Views: 1908
Reputation: 2312
Try
<?php
//make http request
$response = file_get_contents('https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&q=hello%20world&source=en&target=de');
//decode json to array
$json = json_decode($response);
//show the json array in a readable format
echo '<pre>';
//show array
print_r($json);
?>
You can then access specific nodes with echo $json['key_name']
Useful URLs:
http://php.net/manual/en/function.file-get-contents.php
http://php.net/manual/en/function.json-decode.php
Upvotes: 1
Reputation: 335
You could use jQuery and use the $.getJSON, I am no jQuery expert but have used this method several times, it is simple and powerful. Here is the doc for it http://api.jquery.com/jQuery.getJSON/
Upvotes: 0