【发布时间】:2018-09-13 03:11:23
【问题描述】:
我想知道是否可以在 React Native Expo 应用程序上执行 Firebase Cloud Function 中的函数(使用 SDK)?我尝试安装 sdk,但出现了几个错误。 如果没有,有没有其他方法可以做到这一点,没有 SDK?
【问题讨论】:
标签: firebase react-native google-cloud-functions expo
我想知道是否可以在 React Native Expo 应用程序上执行 Firebase Cloud Function 中的函数(使用 SDK)?我尝试安装 sdk,但出现了几个错误。 如果没有,有没有其他方法可以做到这一点,没有 SDK?
【问题讨论】:
标签: firebase react-native google-cloud-functions expo
如果你不想安装任何第三方模块,那么使用 react native 的fetch API:
一个简单的GET 操作是:
fetch('<Your Firebase Cloud Function URL>')
POST 操作将以这种方式完成:
fetch('<Yout Firebase Cloud Function URL>', {
method: 'POST',
headers: {
...
},
body: JSON.stringify({
...
})
})
或者,有一些流行的 3rd 方库,例如 axios。使用命令npm i --save axios 安装它,然后:
import axios from 'axios'
axios.get('<Your Firebase Cloud Function URL>')
或
axios.post('<Your Firebase Cloud Function URL>', {
...
...
})
【讨论】:
exports.someFunction = functions.https.onRequest((req, res) => { // Do whatever you need to do to get the results; return res.status(200).send(...) }
/ Do whatever you need to do to get the results 我只是从数据库中获取用户,然后使用第三方包在客户端中处理它-side 如何使用 Cloud Functions 处理它