我想知道是否可以在 React Native Expo 应用程序上执行 Firebase Cloud Function 中的函数(使用 SDK)?我尝试安装 sdk 但出现几个错误。 如果没有,有没有其他方法可以做到这一点,无需SDK?
最佳答案
如果您不想安装任何第三方模块,请使用React Native的fetch
API:
一个简单的 GET
操作将是:
fetch('<Your Firebase Cloud Function URL>')
POST
操作可以这样完成:
fetch('<Yout Firebase Cloud Function URL>', {
method: 'POST',
headers: {
...
},
body: JSON.stringify({
...
})
})
或者,有一些流行的第三方库,例如axios
。使用命令 npm i --save axios
安装它,然后:
import axios from 'axios'
axios.get('<Your Firebase Cloud Function URL>')
或
axios.post('<Your Firebase Cloud Function URL>', {
...
...
})
关于Firebase 云函数和 React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49636054/