【发布时间】:2018-09-05 09:29:10
【问题描述】:
我正在尝试编写一个从文档中读取的谷歌云函数。
这个函数运行正常,可以返回值:
exports.helloWorld = functions.https.onRequest((request, response) => {
var userArr = [];
fs.collection("user")
.where("user_id", "==", "qIXpbXTuJ5PQHm3rGuTeeSbdnWi1")
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
userArr.push(doc.data());
});
response.send(userArr);
})
.catch(err => {
return err;
});
});
但是这个返回错误:
服务器
exports.matches_people = functions.https.onCall((data, context) => {
var userArr = [];
fs.collection("user")
.where("user_id", "==", "qIXpbXTuJ5PQHm3rGuTeeSbdnWi1")
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
userArr.push(doc.data());
});
return userArr;
})
.catch(err => {
return err;
});
});
客户
var matches_people = firebase.functions().httpsCallable('matches_people');
matches_people({
user_id: self.login.user_id
}).then(function (result) {
// Read result of the Cloud Function.
var sanitizedMessage = result.data.text;
console.log(result);
// ...
}).catch(function (error) {
// Getting the Error details.
var code = error.code;
var message = error.message;
var details = error.details;
console.log(error); //return error: TypeError: Cannot read property 'text' of null
// ...
});
在 httpsCallable 上,它返回错误 TypeError: Cannot read property 'text' of null
请帮忙。
对不起我的英语
【问题讨论】:
标签: firebase google-cloud-firestore google-cloud-functions