Tag: firebase

在云function上创build消息传递主题

我正在尝试为每个新创build的组创build主题。 所以我写这个函数来做这个操作。 exports.createGroupTopic = functions.database.ref("groups/{groupid}/id") .onWrite(event=>{ var groupid = event.params.groupid; request({ url: "https://iid.googleapis.com/iid/v1/my_registration_token/rel/topics/topic_name", headers: { 'Content-Type':'application/json', 'Content-Length': 0, 'Authorization':'my API Key' } }, function (error, response, body){ console.log(response); }); }); 但是,当我运行此代码时,我在Firebase控制台上获得了以下响应日志。 IncomingMessage { _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: […]

Firebase Cloudfunction在特定时间后自动删除数据

我想删除任何两个小时以前的数据。 我知道这个问题已经在这里回答了删除2小时以前的firebase数据 答案是: var ref = new Firebase('https://yours.firebaseio.com/path/to/items/'); var now = Date.now(); var cutoff = now – 2 * 60 * 60 * 1000; var old = ref.orderByChild('timestamp').endAt(cutoff).limitToLast(1); var listener = old.on('child_added', function(snapshot) { snapshot.ref().remove(); }); 但有人可以帮助将其转换为nodejsfunction,我可以部署到firebase云function。

Firebase凭据错误

我有一些错误: 通过\“credential \”属性为initializeApp()提供的凭据实现无法获取有效的Google OAuth2访问令牌,并出现以下错误:\“获取访问令牌时出错:invalid_grant(无效的JWT:令牌必须是短期令牌,在合理的时间内)“。 有两个可能的原因:(1)您的服务器时间未正确同步或(2)您的证书密钥文件已被吊销。 解决(1),重新同步你的服务器上的时间。 要解决(2),请确保您的密钥文件的密钥ID在Firebase项目中仍然存在。 如果不是,则在服务帐户设置中生成一个新的密钥文件。 当我尝试在Nodejs中使用Firebase Admin SDK时。 在我的本地计算机上工作,但是当我尝试在AWS服务器中使用时,出现此错误。 一些小费?

我的AJAX代码(将Firebase令牌发送到服务器)有什么问题?

我是初学者。 我试图通过AJAX从login用户的状态发送的令牌发送。 但是,当我运行下面的代码,我得到内部服务器错误,所以一些东西closures。 我错过了什么? app.post('/auth', function(req,res,next){ var idToken = admin.auth().verifyIdToken(idToken) .then(function(decodedToken) { var uid = decodedToken.uid console.log(uid) res.send(uid) }).catch(function(error) { console.log(error.message) }) }) $("#sign-in").on('click', function(event) { event.preventDefault() var email = $("#email").val() var password = $("#password").val() firebaseAUTH.signInWithEmailAndPassword(email, password).then(function (user) { console.log('user has signed in with e-mail address: '+user.email+' and user ID: '+user.uid) //window.location = '/members-area' firebaseAUTH.currentUser.getToken(true).then(function(idToken) […]

Firebase set()承诺停留在挂起状态

我正在尝试简单地写入Firebase数据库,如下所示: return app.register( email, password ).then( f => { return app.login( email, password ) } ).then( f => { return app.currentUser() } ).then( user => { return app.firebase.db().ref( `users/${user.uid}` ).set( {color: 'red'} ) } ).then( f => { console.log( "This never triggers" ) } ) 其中app.register是: ( firebase, email, password ) => firebase.auth().createUserWithEmailAndPassword( email, password […]

Firebase FCM错误:“InvalidRegistration”

目前,我正尝试使用FCM在Firebase Cloud Functions的帮助下向Device Group发送PushNotification ,但一旦发送通知,它将返回代码200但会失败: SUCCESS response= { multicast_id: 8834986220110966000, success: 0, failure: 1, canonical_ids: 0, results: [ { error: 'InvalidRegistration' } ] } 这里是我用来发送这个通知的代码…我错过了什么? const options = { method: 'POST', uri: 'https://fcm.googleapis.com/fcm/send', headers: { 'Authorization': 'key=' + serverKey, }, body: { to: groupId, data: { subject: message }, notification: { title: title, body: body, […]

使用Firebasefunction更新存储更改上的Firebase数据库

我试图在我的Android应用程序中实现configuration文件图片function。 所以我使用了来自Firebase的“ 生成缩略图”样本。 所以每当我上传一个完整大小的图片,它会为我生成缩略图。 但是我想要在缩略图生成后更新我的实时数据库中的缩略图的URL。 const functions = require('firebase-functions'); const mkdirp = require('mkdirp-promise'); const gcs = require('@google-cloud/storage')(); const spawn = require('child-process-promise').spawn; const LOCAL_TMP_FOLDER = '/tmp/'; // Max height and width of the thumbnail in pixels. const THUMB_MAX_HEIGHT = 100; const THUMB_MAX_WIDTH = 100; // Thumbnail prefix added to file names. const THUMB_PREFIX = 'thumb_'; /** […]

Firebase的云端函数在Algolia中为Firebase数据库对象build立索引

我通过文档,github仓库,但没有为我工作呢。 我的数据结构: App { posts : { <post_keys> : { auth_name : "name", text : "some text" //and many other fields } } } 1) Github存储库 :如果我使用这个,我只从一个函数获得一个字段,如果我需要所有的字段,我将需要为每个函数编写单独的函数,这是一个坏的方法。 2) Algolia Node.js的官方文档 :这不能作为一个云function部署,但它做我打算做的。 我如何编写一个可以在Firebase上部署的函数,并获取在Algolia中使用其密钥索引的整个对象?

节点不会从Firebase数据库中移除?

我有以下数据结构: 不幸的是,“天”不会从下面的代码中删除数据库。 我目前的代码: const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.deleteOldItems = functions.database.ref('/path/to/items/{pushId}') //irrelevant to the question .onWrite(event => { var ref = event.data.ref.parent; // reference to the items var now = Date.now(); var cutoff = now – 2 * 60 * 60 * 1000; var oldItemsQuery = ref.orderByChild('timestamp').endAt(cutoff); return oldItemsQuery.once('value', function(snapshot) { […]

通知不会出现在应用程序的背景状态和死亡状态

我试图在上传post时将通知推送给应用的最终用户。 它在应用程序处于前景时工作正常,但当应用程序在后台或被杀害时不显示。 有什么办法来显示应用程序被杀害或在后台运行的通知。 这里是我使用的node.js代码 const functions = require('firebase-functions'); let admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendPush = functions.database.ref('/promos').onWrite(event => { var topic = "deals_notification"; let projectStateChanged = false; let projectCreated = false; let projectData = event.data.val(); if (((event.data.numChildren())-(event.data.previous.numChildren()))>0) { let msg="notification arrived" let payload = { notification: { title: 'Firebase Notification', body: msg, sound: 'default', badge: '1' […]