我有一个android应用程序,用户数据存储在消防站。我希望用python获取这些数据并操作Google函数(用于排名系统)上的结果,并将这些结果直接发送到Firebase远程Config,这样用户就可以从那里获取数据。
在官方文件中,他们在图片中也显示了同样的东西。
。
但描述完全不同。文档。
因此,我的问题是:我是否可以将在google云功能上计算的结果直接发送到firebase远程配置?
此外,我们还有一个REST来获取和更改Firebase远程Config值。我们可以在Google函数中调用这个api吗?
。我使用这段代码,它需要一个令牌,但是我在基于Remore配置的相同帐户上使用这个云函数。
def _get():
从服务器检索当前Firebase远程Config模板,并在本地存储它。
headers = {
'Authorization': 'Bearer ' + _get_access_token()
}
resp = requests.get(REMOTE_CONFIG_URL, headers=headers)
if resp.status_code == 200:
with io.open('config.json', 'wb') as f:
f.write(resp.text.encode('utf-8'))
print('Retrieved template has been written to config.json')
print('ETag from server: {}'.format(resp.headers['ETag']))
else:
print('Unable to get template')
print(resp.text)
这里是发布数据的代码
`def _publish(etag):
"""Publish local template to Firebase server.
Args:
etag: ETag for safe (avoid race conditions)
"""
with open('**config.json**', 'r', encoding='utf-8') as f:
content = f.read()
headers = {
'Authorization': 'Bearer ' + _get_access_token(),
'Content-Type': 'application/json; UTF-8',
'If-Match': etag
}
resp = requests.
put(REMOTE_CONFIG_URL,
data=content.encode('utf-8'),headers=headers)
if resp.status_code == 200:
print('Template has been published.')
print('ETag from server: {}'.format(resp.headers['ETag']))
else:
print('Unable to publish template.')
print(resp.text)`
就像我可以在云函数中访问没有身份验证的数据库一样,为什么不能在没有config.json的情况下更新远程配置呢?函数只有两个文件、main.py、和。
如果云功能需要进行身份验证才能更新远程Config,那么我可以在哪里存储config.json文件?
发布于 2021-12-31 10:57:34
在需要的时候,您似乎会手动触发该函数。您可以创建一个HTTP函数,并验证是您触发了它,这样其他人就不会触发它了。
from flask import escape
import functions_framework
def update_data_http(request):
# 1. Verify the function is called by you
# 2. Perform the calculations
# 3. Update the result in Remote Config / Realtime Database
return 'Data updated!!'
不包括远程Config,因此您必须使用远程Config REST来更新数据。为此使用实时数据库可能要容易一些,因为您可以使用Admin直接更新数据。
我是否可以将在google云功能上计算的结果直接发送到firebase远程配置?
是的,使用上面链接的REST。
我们可以在Google函数中调用这个api吗?
您可以从云函数中调用任何API。有关使用Python:使用python向RESTful API发出请求调用API的答案,请参阅此答案
https://stackoverflow.com/questions/70540609
复制相似问题