我想訪問Google Translate APIv2。這裏是網址:調用Google翻譯API的REST方法
我已經有鑰匙,此網址的,如果我在瀏覽器地址欄中使用它做工精細。
我的問題是,我不知道如何使用REST調用此URL。我想將結果存儲在一個變量中。
我想訪問Google Translate APIv2。這裏是網址:調用Google翻譯API的REST方法
我已經有鑰匙,此網址的,如果我在瀏覽器地址欄中使用它做工精細。
我的問題是,我不知道如何使用REST調用此URL。我想將結果存儲在一個變量中。
嘗試
<?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);
?>
然後,您可以訪問特定的節點與echo $json['key_name']
有用網址:
最簡單的方法是file_get_contents。
您可以使用jQuery並使用$ .getJSON,我不是jQuery專家,但多次使用此方法,它非常簡單且功能強大。這裏是DOC它http://api.jquery.com/jQuery.getJSON/