node.js - 使用 Firebase 函数访问 API 数据
问题描述
我正在尝试从 API 中提取数据并将其存储在变量中。我正在使用 firebase 函数、IEXCloud 和 node.js,但我无法访问正文中的数据。该链接在我单独使用时有效,如果我从链接中删除 .body ,则该链接将发送到浏览器。
这就是我所拥有的:
const functions = require("firebase-functions");
const sA = "https://sandbox.iexapis.com/stable/";
const key = "(API-Key)";
exports.symbol = functions.https.onRequest((request, response) => {
const symbol = (`${sA}stock/aapl/quote?token=${key}`).body;
response.send(symbol);
});
解决方案
您没有在这里调用任何 API const symbol = (
${sA}stock/aapl/quote?token=${key} ).body;
。
你的意思是打电话给fetch()
:
exports.symbol = functions.https.onRequest((request, response) => {
return fetch(`${sA}stock/aapl/quote?token=${key}`).then((res) => {
symbol = res.body;
response.send(symbol);
});
});
推荐阅读
- python - 如何使用 python 和 selenium webdriver 遍历表并打印前 10 行的结果?
- python-3.x - 如何检查布尔熊猫系列中的所有值是否属于一种类型并根据if条件应用逻辑?
- java - android app下载apk文件并打开(安装)
- go - Golang:用于重新连接 TCP 客户端的递归函数......坏主意?
- python - 如何根据数独条件删除字典值删除错误值?
- python - 在数组数组中查找所有可能的项目组合
- java - 我在 println 中不断收到“错误:找不到符号”
- dart - Flutter:在 StatelessWidget 中哪里添加监听器?
- excel - Excel/Sheets 根据相邻单元格添加和列出单元格值
- python - 如何将带有文字十六进制的字符串转换为十六进制?