Google の Calculator API を使用しています。以下のように動的な値を Google の URL に渡す必要があります。
$url = 'http://www.google.com/ig/calculator?hl=en&q=' . urlEncode($amount . $currency . '=?' . $exchangeIn);
しかし、私はグーグルから次の例外を受けています。
Warning: file_get_contents(http://www.google.com/ig/calculator?hl=en&q=13,000,000pkr=?cad) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable in /home/..../public_html/config/config.php on line 48
これに対する私の機能は次のとおりです。
function exchangeRate($amount, $currency, $exchangeIn) {
$url = 'http://www.google.com/ig/calculator?hl=en&q=' . urlEncode($amount . $currency . '=?' . $exchangeIn);
$data = file_get_contents($url);
if(!$data) {
throw new Exception('Could not connect');
}
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$array = $json->decode($data);
if(!$array) {
throw new Exception('Could not parse the JSON');
}
if($array['error']) {
throw new Exception('Google reported an error: ' . $array['error']);
}
return number_format($array['rhs']);
}
echo exchangeRate('9,200,000', 'pkr', 'cad')
誰かが私のコードに問題があるのか 、このGoogle APIに何か問題があるのでしょうか?
ありがとう