Subscribe to a stream with RxJS and twitter-stream-api module

后端 未结 2 1355
一生所求
一生所求 2021-01-15 16:27

Ok, so I\'m a complete beginner with Rx and unfortunately very new to js and streams in js as well. Im using this https://github.com/trygve-lie/twitter-stream-api to connect

2条回答
  •  不思量自难忘°
    2021-01-15 16:57

    Here's an example using desmondmorris/node-twitter and rxjs 5.

    const Observable = require('rxjs').Observable;
    
    Observable
      .of(new require('twitter')({
        consumer_key: 'xxxx',
        consumer_secret: 'xxxx',
        access_token_key: 'xxxx',
        access_token_secret: 'xxxx',
      })).mergeMap(twitter =>
        Observable
        .fromEvent(twitter.stream('statuses/filter', {
            track: 'Stack Overflow'
          }),
          'data'))
      .filter(tweet => tweet.user.follow_count > 10000)
      .subscribe(console.log);

提交回复
热议问题