node.js - 使用 NodeJS 实现 Twitter API

标签 node.js twitter node-modules twitterapi-python twitter-api-v2

我正在尝试开发一个 NodeJS 应用程序,我希望能够搜索包含关键字的推文,这是我的代码:

const express = require("express");
const app = express();
var Twitter = require("twitter");
const needle = require('needle');

var client = new Twitter({
  consumer_key: "key",
  consumer_secret: "key",
  access_token_key: "key",
  access_token_secret: "key",
});

app.listen(3000, () => {
  console.log("Server is running on port 3000");
});

app.get("/search", (req, res) => {
    client.get('2/search/tweets', {q: 'node.js'}, function(error, tweets, response) {
        console.log(tweets);
        console.log(error)
     });
});

当我尝试通过 postman 向我的 Node 应用程序发送请求时,答案是这样的:

{}
Error: HTTP Error: 404 Not Found
    at Request._callback (C:\Users\nikos\Desktop\node_modules\twitter\lib\twitter.js:221:9)
    at Request.self.callback (C:\Users\nikos\Desktop\node_modules\request\request.js:185:22)
    at Request.emit (node:events:527:28)
    at Request.<anonymous> (C:\Users\nikos\Desktop\node_modules\request\request.js:1154:10)
    at Request.emit (node:events:527:28)
    at IncomingMessage.<anonymous> (C:\Users\nikos\Desktop\node_modules\request\request.js:1076:12)
    at Object.onceWrapper (node:events:641:28)
    at IncomingMessage.emit (node:events:539:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

如果有人可以提供帮助,我将非常感激,因为我在过去 3 天里一直在尝试解决如何正确使用此 api 的问题。提前致谢!

最佳答案

您检查过 GitHub 中的代码示例吗? ?

关于node.js - 使用 NodeJS 实现 Twitter API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72803974/

相关文章:

Node.js安装Synology ds212+报错

javascript - 将setTimeout()函数从JSDOM更改为node.js默认值?

javascript - 使用 Google Analytics 跟踪网站上的社交推文

asp.net-core - Gitlab CI : Skipping cache archiving due to empty cache key

javascript - Tailwind CSS 不适用于 React App

javascript - 如何在 Grunt 中将项目变量 config.get() 到任务的 initConfig 中?

javascript - 作为参数传递的函数的系统唯一 ID (javascript)

iphone - 如何解决 iPhone 中 Twitter 集成中的 "LibXml/xmlreader.h Not found"错误

api - 为大型用户群获取 Twitter 好友列表和管理速率限制的设计

webpack - webpack 如何解析从 node_modules 的导入?