為替レートAPIのexchangeratesapiの代わり(2021/4)
アプリが動かない!
アプリが動かなくなりましたというご報告をいただき、調査したところ、為替レート取得でエラーになっていました。
原因
下のサイトを利用していたのですが、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];
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を使う定めなのか、変更リスクはありますね。
使えなくなってからでしか、気が付かない。。。
めでたしめでたし
Author And Source
この問題について(為替レートAPIのexchangeratesapiの代わり(2021/4)), 我々は、より多くの情報をここで見つけました https://qiita.com/kazutxt/items/8dacc3fcf3c67fff96fe著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .