Firebase函数v2触发器使用Python脚本实时数据库不起作用。

huangapple go评论54阅读模式
英文:

firebase function v2 trigger for realtimedatabase using a python script is not working for me

问题

I am trying to use python with firebase functions. I already have a function running for my webhooks. but I tried to add another function to run when a new record is created on RealtimeDatabase, without success.

我正在尝试使用Python与Firebase函数。我已经有一个用于我的Webhooks的函数在运行,但我尝试添加另一个函数以在实时数据库上创建新记录时运行,但没有成功。

I tried using the CLI at first, following the steps and using this code from the quickstart :

我首先尝试使用CLI,按照步骤并使用快速入门中的代码:

from typing import Any

The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.

from firebase_functions import db_fn

The Firebase Admin SDK to access the Firebase Realtime Database.

from firebase_admin import initialize_app, db

app = initialize_app()

@db_fn.on_value_written(reference="/Stores/{storeID}")
def onwrittenfunctiondefault(event: db_fn.Event[db_fn.Change]) -> None:
print(event.data)

You can see I switched to on_value_written to catch any change on the path Stores/{storeID}
I don't know what am i missing..

您可以看到,我切换到on_value_written以捕获路径Stores/{storeID}上的任何更改,但我不知道我漏掉了什么。。

I also tried to create the function from google cloud console, created the eventarc trigger and it was deployed successfully. but when I add anything to the database, it is not triggered.

我还尝试从Google Cloud控制台创建函数,创建了Eventarc触发器,并成功部署了它,但当我向数据库添加任何内容时,它不会触发。

Does anyone have an idea what I need to do?

有人知道我需要做什么吗?

英文:

I am trying to use python with firebase functions. I already have a function running for my webhooks. but I tried to add another function to run when a new record is created on RealtimeDatabase, without success.

I tried using the CLI at first, following the steps and using this code from the quickstart :

from typing import Any
# The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.
from firebase_functions import db_fn

# The Firebase Admin SDK to access the Firebase Realtime Database.
from firebase_admin import initialize_app, db

app = initialize_app()


@db_fn.on_value_written(reference="/Stores/{storeID}")
def onwrittenfunctiondefault(event: db_fn.Event[db_fn.Change]) -> None:
    print(event.data)

You can see I switched to on_value_written to catch any change on the path Stores/{storeID}
I don't know what am i missing..

I also tried to create the function from google cloud console, created the eventarc trigger and it was deployed successfully. but when I add anything to the database, it is not triggered.

Does anyone have an idea what I need to do?

答案1

得分: 1

这是我做的事情:
我为我的Firebase帐户获得了所有者权限(也许这与问题无关!)
然后我删除了我的脚本,从快速入门中复制了完整的脚本。

现在我可以在日志中看到函数被触发并正常工作。但是,当我尝试修改路径以类似以下的方式时:/messages/{pushId}/original/{type}
函数失败了,它被触发但失败了。
在末尾添加{type}会引发问题。不过,这本来也不是主要要求。

英文:

Here is what i did :
I got owner permissions for my firebase account . ( maybe it is irrelevant! )
and I deleted my script, copied the full script from quickstarts

Now I can see in the logs that the function is triggered and working. However, when I tried to modify the path to be something like : /messages/{pushId}/original/{type}
the function failed, it was triggered but failed.
adding {type} at the end was causing a problem. It wasn't a main requirement anyway .

huangapple
  • 本文由 发表于 2023年5月25日 19:56:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定