【问题标题】:How to do listening node js port for the Twitter API如何为 Twitter API 做监听节点 js 端口
【发布时间】:2018-07-21 03:02:25
【问题描述】:

下面是代码。如何在 Postman 中运行以下服务(如何监听以下服务)。我可以在 console.log 中打印数据

从 config.default 我获取 consumer_key、c​​onsumer_secret、access_token_key、access_token_secret

var Twitter = require('twitter');
var config = require('./config.default');
console.log(config);
var T = new Twitter(config);

// Set up your search parameters
var retweet = function () {
var params = {
  q: '#FIFA2018',
  count: 10,
  result_type: 'recent',
  lang: 'en'
}
T.get('search/tweets', params, function (err, data) {
      // if there no errors
      if (!err) {
        // grab ID of tweet to retweet
        console.log(data);
        var retweetId = data.statuses[0].id_str;
        // Tell TWITTER to retweet
        T.post('statuses/retweet/:id', {
          id: retweetId
        }, function (err, response) {
          if (response) {
            console.log('Retweeted!!!');
          }
          // if there was an error while tweeting
          if (err) {
            console.log('Something went wrong while RETWEETING... Duplication maybe...');
          }
        });
      }
      // if unable to Search a tweet
      else {
        console.log('Something went wrong while SEARCHING...');
      }
    });
}

retweet();
// retweet in every 50 minutes
setInterval(retweet, 30000);

【问题讨论】:

    标签: node.js express


    【解决方案1】:

    通过 npm install 检查你安装了 twitter 库的 node_modules。在 twitter 下,您将看到一个 lib(库)文件夹。您可以检查 twitter.js 文件。该文件将列出所有功能。此外,您还可以看到用作基础的不同 URL。

    this.options = extend({
        consumer_key: null,
        consumer_secret: null,
        access_token_key: null,
        access_token_secret: null,
        bearer_token: null,
        rest_base: 'https://api.twitter.com/1.1',
        stream_base: 'https://stream.twitter.com/1.1',
        user_stream_base: 'https://userstream.twitter.com/1.1',
        site_stream_base: 'https://sitestream.twitter.com/1.1',
        media_base: 'https://upload.twitter.com/1.1',
        request_options: {
          headers: {
            Accept: '*/*',
            Connection: 'close',
            'User-Agent': 'node-twitter/' + VERSION
          }
        }
      }, options);

    您可以根据要使用的功能使用 URL。您必须根据您使用的 API 提供请求标头和有效负载。

    【讨论】:

    • 是的,我知道了。但我的问题是如何为上述服务制作监听器
    • 监听器是什么意思,可以举个例子吗?
    猜你喜欢
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-10-29
    • 1970-01-01
    • 2011-12-15
    • 2013-03-29
    • 2019-04-25
    相关资源
    最近更新 更多