Google currency converter API - will it shut down

2019-03-16 11:01发布

问题:

iGoogle is shutting down.

There is an (undocumented?) currency conversion API available with URLs like: http://www.google.com/ig/calculator?hl=en&q=1GBP=?USD

The base of this url - google.com/ig - takes you to iGoogle. Will the API be available after iGoogle shuts down?

回答1:

I was having the same issue described here: https://stackoverflow.com/a/19786423/2819754

I used @hobailey answer for a temporary fix until i can update it to another version or google decide to do a proper api.

As google changed the URL to

  https://www.google.com/finance/converter?a

So the fix i found is below.

  $amount = urlencode($amount);
  $from_Currency = urlencode($from_Currency);
  $to_Currency = urlencode($to_Currency);
  $get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
  $get = explode("<span class=bld>",$get);
  $get = explode("</span>",$get[1]);  
  $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);

thanks to @hobailey for this little fix.



回答2:

Alternatively you can use following:

  • http://rate-exchange.appspot.com/currency?from=CAD&to=USD

  • http://rate-exchange.herokuapp.com/fetchRate?from=CAD&to=USD

But the first one is not that stable goes out of capacity very often. We had an extreme problem in our production environment using the first exchange service few months back. So far second one is stable, doesn't cause any problem.



回答3:

iGoogle has already expired but not the gadget link you have posted. Currently it returns 200 OK with probably your desired message.

Update: It got expired too. No Gadgets are available at the moment.

Update: Available from here https://www.google.com/finance/converter?a=16.6700&from=GBP&to=USD



回答4:

Free Currency Converter API from http://mycurrency.net

  • It is 100% Free.
  • No API key is required!
  • No cap on frequency of API calls.
  • Currency price is updated every two hours.
  • Support json format.
  • Very fast and reliable.
  • The api address is here. It returns 176 currencies prices together with country name, country code, currency name and currency price. The base currency is USD.

    http://www.mycurrency.net/service/rates

There is also Free country flag API you may also need. Just replace the country code.

http://caches.space/flags/{countrycode}.png

Example:

http://caches.space/flags/sg.png

http://caches.space/flags/us.png



回答5:

Just use this URL

https://finance.google.com/bctzjpnsun/converter?a=1&from=USD&to=INR

Replace

 https://www.google.com/finance/

to

https://finance.google.com/bctzjpnsun/