我正在尝试开发一个 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/