skip to Main Content

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:UsersnikosDesktopnode_modulestwitterlibtwitter.js:221:9)
    at Request.self.callback (C:UsersnikosDesktopnode_modulesrequestrequest.js:185:22)
    at Request.emit (node:events:527:28)
    at Request.<anonymous> (C:UsersnikosDesktopnode_modulesrequestrequest.js:1154:10)
    at Request.emit (node:events:527:28)
    at IncomingMessage.<anonymous> (C:UsersnikosDesktopnode_modulesrequestrequest.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!

2

Answers


  1. have you checked out the code samples in GitHub?

    Login or Signup to reply.
  2. Try using the official Twitter API v2 JavaScript SDK:
    https://github.com/twitterdev/twitter-api-typescript-sdk

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search