node.js - Axios 写入 Firebase 时返回 401 错误
问题描述
我目前有一个计划函数作为云函数运行,它使用 Axios 写入 Firebase 中的实时数据库。但是,我继续收到错误:
'请求失败,状态码 401'
这似乎是一个授权错误。我正在使用 Axios 并使用遗留令牌进行授权,特别是数据库的秘密。
我在这里使用授权错误还是有其他方法可以做到这一点?我遇到的问题是在预定功能中使用授权访问。
应用程序.js
exports.callTo = functions.pubsub.schedule("* * * * *").onRun((context) => {
let searchTrends;
googleTrends.dailyTrends({
trendDate: new Date("2021-10-20"),
geo: "US",
}, function(err, res) {
if (err) {
functions.logger.error(err);
} else {
searchTrends = JSON.parse(res).default.trendingSearchesDays
.trendingSearches;
const query = searchTrends[2] + " since:2021-10-20";
return axios.put("https://testtter-c0e48-default-rtdb.firebaseio.com/searchTrends.json?auth=<account_secret>", {trends: searchTrends})
.then((res) => {
functions.logger.log("Result: " + res);
})
.catch((error) => {
functions.logger.log("Error: " + error);
});
}
});
});
解决方案
推荐阅读
- javascript - 分享页面链接
- sql-server - 从 Powershell 执行 SQL 查询时出错
- node.js - IIS 节点在更改时自动启动并保持活动状态
- python - Python:将保留文件格式的txt文件中的每个句子大写
- javascript - Javascript表格过滤器不显示表格标题
- javascript - 使用 K 意味着根据领导者的得分将人们映射到一个组
- database - 一条记录和表之间的连接 - MS Access
- javascript - 为什么在 cypress.io 中拖放不能按预期工作?
- cucumber - 空手道 DSL - 需要在 POST 请求中传递当前日期和过去日期作为参数
- android - 警报和声音在博览会推送通知中不起作用