我想打印BTC转换到其他货币。我用的是bitcoinaverage。在浏览器上,URL不工作。屏幕显示“不允许未经身份验证的请求”。制定一个新的计划,或者在https://pro。bitcoinaverage。com上开始免费试用。”我用的是颤振在控制台,它给出一个404错误。下面是代码片段。
const bitcoinAverageURL = 'https://apiv2.bitcoinaverage.com/indices/average/ticker';
Future getCoinData(String selectedCurrency) async {
var authKey = '$bitcoinAverageURL/BTCAUD';
http.Response response = await http.get(Uri.parse(authKey));
if (response.statusCode == 200) {
var decodedData = jsonDecode(response.body);
double current = decodedData['last'];
return current.toStringAsFixed(0);
} else {
print(response.statusCode);
throw 'Problem with get request';
}
从文档:# # #
All requests to our API must be authenticated with your public key.
你需要在API站点上授权并获得你的API访问令牌。官方文档中描述的API用法。
尝试添加你的API键头:
await http.get(
Uri.parse(url),
headers: {
'x-ba-key': 'your_api_key',
},
);