LoginSignup
0
2

More than 3 years have passed since last update.

為替レートAPIのexchangeratesapiの代わり(2021/4)

Last updated at Posted at 2021-04-08

アプリが動かない!

アプリが動かなくなりましたというご報告をいただき、調査したところ、為替レート取得でエラーになっていました。

原因

下のサイトを利用していたのですが、2021/4から?認証が必要になっていました。
https://exchangeratesapi.io/

無料枠では、250/月では少し足りないかなと思い、探し回りました。

代わりを探そう

あちこち探し回りましたが、見つからない。。。

でも、ようやく見つかる。

いつも使っている海外の仮想通貨取引所のBitifinexの公開APIにあったので、差し替えたら無事に動きました
https://docs.bitfinex.com/reference#rest-public-calc-foreign-exchange-rate

実装を直す

old.dart
http.Response resp1 =
        await http.get("https://api.exchangeratesapi.io/latest?base=USD");
    return json.decode(resp1.body)['rates']['JPY'];
new.dart
Map<String, String> headers = {"content-type": 'application/json'};
String body = json.encode({'ccy1': 'USD', 'ccy2': 'JPY'});
http.Response resp1 = await http.post("https://api.bitfinex.com/v2/calc/fx", headers: headers, body: body);
return json.decode(resp1.body)[0];

外部APIを使う定めなのか、変更リスクはありますね。
使えなくなってからでしか、気が付かない。。。

めでたしめでたし

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2