在Firebase中为Twitter流API运行Node.JS后台进程 [英] Running a Node.JS background process for Twitter streaming API in Firebase

查看:76
本文介绍了在Firebase中为Twitter流API运行Node.JS后台进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Node.JS脚本部署到Firebase,该脚本使用Twitter的流API侦听新的tweet,然后将每个tweet存储在Firebase数据库中.如何部署此脚本并确保其运行24/7?

I want to deploy a Node.JS script to Firebase that listens for new tweets using Twitter's streaming API, and then stores each tweet in the Firebase Database. How do I deploy this script and make sure that it runs 24/7?

作为示例,请考虑以下基于NPM Twit 包的(简化)代码:

As an example, consider the following (simplified) code, based on NPM Twit package:

var stream = T.stream('statuses/sample')

stream.on('tweet', function (tweet) {
  // write data to Firebase Database here
})

我查看了 Firebase Cloud函数,但这不是我想要的,因为它们由事件触发.我还看到有 Firebase队列,但我并不是真的想将进程排队:我只希望它一直运行. Firebase托管目前可以做到这一点吗?

I looked into Firebase Cloud functions, but that's not what I want, because they are triggered by an event. I also saw there is Firebase Queue, but I don't really want to queue the process: I just want it to run all the time. Is this possible currently with Firebase hosting?

一种替代方法是使用 IFTTT 创建一个称为Webbook的Twitter食谱.但是,我想存储来自许多不同用户的推文,因此这不是一个非常灵活的解决方案.

An alternative would be to create a Twitter recipe with IFTTT that calls a Webbook. However, I want to store tweets from many different users, so it's not a very flexible solution.

推荐答案

Firebase托管无法运行任何代码. Cloud Functions可以运行代码,但不能无限期地运行代码,并且只能响应定义的触发器.

Firebase Hosting can't run any code. Cloud Functions can run code, but not indefinitely, and only in response to defined triggers.

请考虑使用带有云功能的多个IFTTT作为Webhook,以接收满足某些搜索条件的推文,在该项目中执行.如果需要将多个查询汇总到一个位置,则可以设置多个IFTTT小程序.如果您不想维护自己的服务器,这可能是最好的选择.

Consider instead using multiple IFTTT with a Cloud Function as a webhook to receive tweets that meet some search criteria, as implemented in this project. You can set up multiple IFTTT applets if you need multiple queries to be aggregated in one place. This may be your best bet if you don't want to maintain your own server.

这篇关于在Firebase中为Twitter流API运行Node.JS后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆