0

I m trying to extract data from this url

https://twitter.com/i/tfb/v1/tweet_activity/web/poll/968074591301140480

When i hit this url in browser is start downloading a .json file.

But i want to read this data in node.js.

I m stuck in this. Please, Help me out.

vikash5472
  • 200
  • 2
  • 16

1 Answers1

1

Well easy enough, Just download the file and do this:

var json = require('./yourfile.json');

Node will automatically parse this json and now you can access it.

console.log(json);

Here's one example, i did myself.

Now, If you want to do this dynamically by that i mean for user in node.js:

You can do it like this:

First install an http middleware, such as node-fetch

npm install node-fetch

Now you'd go into node and run this up:

var fetch = require('node-fetch');



fetch(`https://twitter.com/i/tfb/v1/tweet_activity/web/poll/USER_ID_HERE`)
.then(res => res.json)
.then((json) => {
      // u have your json here now, u can use it here.
 })
Daksh M.
  • 4,589
  • 4
  • 30
  • 46