php - Error while implementing currency converter of yahoo -
php - Error while implementing currency converter of yahoo -
<?php error_reporting(0); $currency_code = $_get['currency_code']; $currency_opt = strtoupper($currency_code)."inr"; $jsn_response = file_get_contents('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22' .$currency_opt. '%22%29&format=json&env=store://datatables.org/alltableswithkeys&callback='); $currencyrate_arr = json_decode($jsn_response, true); $currency_rate = $currencyrate_arr['query']['results']['rate']['rate']; //var_dump($currency_rate); if($currency_rate > 0){ echo $currency_text = $currency_rate; } else{ echo $currency_text = "sorry! error.."; } ?>
it working fine getting error while using piece of code currency conversion.
the script working me, , produces right results.
if receiving error, it's either because of server configuration, or api limit.
you can check https://developer.yahoo.com/yql/faq/
rate limits in yql based on authentication. if utilize ip-based authentication, limited 2,000 calls/hour/ip public yql web service url (/v1/public/*)
if need exceed 2000 calls per hr limit, read above link more information.
ps: if want debug, set:
error_reporting(e_all); ini_set('display_errors', 1);
edit: since allow_url_fopen
disabled, can't utilize file_get_contents
on outside urls, can still utilize curl.
so replace file_get_contents
with:
$ch = curl_init(); curl_setopt($ch, curlopt_url, 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22' .$currency_opt. '%22%29&format=json&env=store://datatables.org/alltableswithkeys&callback='); curl_setopt($ch, curlopt_returntransfer, true); $jsn_response = curl_exec($ch); curl_close($ch);
php
Comments
Post a Comment