简体   繁体   中英

Implementing Twitter API with NodeJS

I am trying to develop a NodeJS app and i want to be able to search for tweets including a keyword here is my code:

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)
     });
});

when i try via postman to send a request to my node app the answer is this:

{}
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)

If anyone can help i would greatly appreciate it since i am trying to solve how to use this api properly for the last 3 days. Thanks in advance

have you checked out the code samples in GitHub ?

Try using the official Twitter API v2 JavaScript SDK: https://github.com/twitterdev/twitter-api-typescript-sdk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM