Tag: google cloud functions

Firebase云端function总是超时

我正在探索Firebase云计算function,并试图通过http请求发送通知。 问题是,即使我设法发送通知,请求总是超时。 这是我的脚本 const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.friendRequestNotification = functions.https.onRequest((req, res) => { const senderId = req.query.senderId; const recipientId = req.query.recipientId; const getRecipientPromise = admin.database().ref(`/players/${recipientId}`).once('value'); const getSenderPromise = admin.database().ref(`/players/${senderId}`).once('value'); return Promise.all([getRecipientPromise, getSenderPromise]).then(results => { const recipient = results[0]; const sender = results[1]; const recipientToken = recipient.child("notificationsInfo/fcmToken").val(); const notificationAuthorization = recipient.child("notificationsInfo/wantsToReceiveNotifications").val(); […]

Firebase云端函数:增量计数器

使用事务处理实时数据库触发器增加计数器是否可以接受? exports.incPostCount = functions.database.ref('/threadsMeta/{threadId}/posts') .onWrite(event => { admin.database().ref('/analytics/postCount') .transaction(count => { if (count === null) { return count = 1 } else { return count + 1 } }) });

Firebase的云端function:pipe理员与根查找

掌握Firebase和JavaScript以编码云function; 但我想我正在寻找是否有人可以解释使用以下查找和/或写入云function的优点和缺点?! 使用admin.database().ref() VS root.child() 我自己一直在使用admin.database.ref() ,但我需要? 使用root.child()而不是同样好?

如何在Firebase的Cloud Functions中创buildHTTP请求?

我正尝试使用Cloud Functions for Firebase拨打电话给苹果收据validation服务器。 任何想法如何进行HTTP调用?

Firebase云端函数:“错误:无法处理请求”

我想把头发拉出来, 这要么是超级简单,要么是脑冻结,要么不是那么简单。 我想要的是 我正尝试使用firebase取消暂停缩短的url,当用户转到: myapp.firebaseappurl.com/url/SHORTENEDLINK 所以不会让我添加一个缩短的url 我想输出是: { "url": "https://stackoverflow.com/questions/45420989/sphinx-search-how-to-use-an-empty-before-match-and-after-match" } 我曾经尝试过 firebase.json文件: { "hosting": { "public": "public", "rewrites": [ { "source": "/url/:item", "destination": "/url/:item" } ] } } index.js文件: const functions = require('firebase-functions'); exports.url = functions.https.onRequest((requested, response) => { var uri = requested.url; request({ uri: uri, followRedirect: true }, function(err, httpResponse) { if (err) […]

Firebase云端函数 – 序列化返回值时出错:

我有一个云function用来交叉引用两个列表,并find在列表中相互匹配的值。 该函数似乎正常工作,但在日志中,我不断看到这个Error serializing return value: TypeError: Converting circular structure to JSON 。 这是function… exports.crossReferenceContacts = functions.database.ref('/cross-ref-contacts/{userId}').onWrite(event => { if (event.data.previous.exists()) { return null; } const userContacts = event.data.val(); const completionRef = event.data.adminRef.root.child('completed-cross-ref').child(userId); const removalRef = event.data.ref; var contactsVerifiedOnDatabase ={}; var matchedContacts= {}; var verifiedNumsRef = event.data.adminRef.root.child('verified-phone-numbers'); return verifiedNumsRef.once('value', function(snapshot) { contactsVerifiedOnDatabase = snapshot.val(); for (key […]

如何获取Firebase云服务器中的服务器时间戳记?

我知道你可以在web,ios和android中获取服务器的时间戳,但是Firebase的新的云端函数呢? 我无法弄清楚如何获得服务器时间戳? 使用案例是我想要时间戳邮件到达时。 在网上它是Firebase.database.ServerValue.TIMESTAMP 但是,这似乎并没有在function节点服务器接口中可用? 我觉得已经很晚了,我可能会错过这里的观点。 编辑 我正在初始化 admin.initializeApp(functions.config().firebase); const fb = admin.database() 那就这样叫 Firebase.database.ServerValue.TIMESTAMP 但是,这是从客户端整合。 在函数上,Firebase不会像这样初始化。 我试过了 admin.database().ServerValue.TIMESTAMP 和 fb.ServerValue.TIMESTAMP

Firebase函数 – getaddrinfo ENOTFOUND api.sandbox.paypal.com

尝试使用PayPal-node-SDK向Paypal的API发出请求 exports.requestPayment = functions.https.onRequest((req, res) => { return new Promise(function (fullfilled, rejected) { paypal.payment.create(create_payment_json, {}, function (error, payment) { if (error) { rejected(error); } else { console.log("Create Payment Response"); console.log(payment); res.status(200).send(JSON.stringify({ paymentID: payment.id })).end(); fullfilled(payment); } }); }); }); 但我不断得到一个错误: Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26) 我试过的东西: 请求一个完全不同的主机,仍然ENOTFOUND […]

Firebase云端函数数据库触发器“onCreate不是函数”

为了效率,我想使用onCreate方法而不是onWrite ,但是我面对这个错误: functions.database.ref(…)。onCreate不是一个函数 。 但是,似乎有一个函数在文档中提到https://firebase.google.com/docs/reference/functions/functions.database.RefBuilder#onCreate 我的代码开始如下: const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.manager = functions.database.ref('some_ref') .onCreate(event =>{ 我期待着你的帮助。 提前致谢。

从使用Cloud Functions for Fire上传的文件获取下载url

在Firebase存储中使用Firebasefunction上传文件后,我想获取文件的下载url。 我有这个 : … return bucket .upload(fromFilePath, {destination: toFilePath}) .then((err, file) => { // Get the download url of file }); 目标文件有很多参数。 即使一个名为mediaLink 。 但是,如果我尝试访问这个链接,我得到这个错误: Anonymous users does not have storage.objects.get access to object … 有人可以告诉我如何获得公共下载url? 谢谢