gpt4 book ai didi

javascript - Firebase-Function - 计划函数不断抛出错误 "UNAUTHENTICATED"

转载 作者:行者123 更新时间:2023-12-03 12:12:48 26 4
gpt4 key购买 nike

我正在制作一个“预定的”firebase 函数,它从外部 API 源获取数据并将其保存在 firestore。

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const { default: Axios } = require("axios");
admin.initializeApp();

exports.getIndexData = functions.pubsub.schedule('every 5 minutes').onRun(async() => {

try {
const response = await Axios(
"https://financialmodelingprep.com/api/v3/quotes/index?apikey=myAPIKEY"
);
const data = response.data;

const writeResult = await admin
.firestore()
.collection("index")
.doc("sorted-index")
.set({ indexData: data,timeStamp:Date.now()});

} catch (error) {
console.log(error);
}
return null;

});

这是我的 firebase 功能代码。当我单独运行该功能时它完全正常,并且我使用“谷歌云平台云功能测试”测试了该功能。当我单独运行一个函数时,数据已成功设置在 firestore。
但是,当我部署该功能时它不起作用,我认为这是关于预定功能的东西
{
"insertId": "184t0npf9hhej7",
"jsonPayload": {
"pubsubTopic": "projects/my-project/topics/firebase-schedule-getIndexData-us-central1",
"targetType": "PUB_SUB",
"status": "UNAUTHENTICATED",
"jobName": "projects/my-project/locations/us-central1/jobs/firebase-schedule-getIndexData-us-central1",
"@type": "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"
},
"resource": {
"type": "cloud_scheduler_job",
"labels": {
"job_id": "firebase-schedule-getIndexData-us-central1",
"project_id": "my-project",
"location": "us-central1"
}
},
"timestamp": "2020-12-09T08:48:01.142830977Z",
"severity": "ERROR",
"logName": "projects/my-project/logs/cloudscheduler.googleapis.com%2Fexecutions",
"receiveTimestamp": "2020-12-09T08:48:01.142830977Z"
}
所以我一直在寻找这个 UNAUTHENTICATED 错误,人们说我需要更改一些权限选项。所以我给了 allUsers 和 allAuthenticated Users 一个 Cloud Functions Invoker 权限。还是行不通。
对此有任何想法或解决方案吗?谢谢你。

最佳答案

您忘记在论点中包含“上下文”。
https://firebase.google.com/docs/functions/schedule-functions

.onRun(async (context) => { ... })

关于javascript - Firebase-Function - 计划函数不断抛出错误 "UNAUTHENTICATED",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65213576/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com