DEV Community

Bryan Hughes for Microsoft Azure

Posted on

twitter-replies-parser - A Tool for Converting Twitter Replies into JSON

Some of my teammates and I recently asked Node.js folks on Twitter what tools they used and why the liked them. We're collecting this so we can help our product teams at Microsoft create better Node.js tools for Azure that serve you, the community. Turns out, lots of folks have a lot of great opinions and feedback on this subject. This is great!

What's not so great is that we had so many replies we couldn't just copy-paste them from the web client 😱. So what to do? Write some JavaScript, of course!

It was a little easier said than done though. As it turns out, Twitter doesn't have any APIs available to get the replies to a tweet. Instead, I had to use the search API and then create the reply tree by hand. With a little coding work and a handful of recursive calls, I got it all working to a high degree of accuracy. Due to the approach used, it's not 100% accurate. I noticed about 2-3 tweets were missing out of the ~60 replies to my request for feedback, but close enough!

This tool is a Node.js application that spins up a web server with a simple web app for entering the URL of the tweet you want to get the replies to. It's definitely not pretty, but get's the job done:

Screenshot of the web UI for Twitter Replies Parser

You can check out the tool on GitHub, which is released under the MIT open source license. I'd love to hear what you think, and if you run into any issues using it.

Oldest comments (4)

Collapse
 
john_papa profile image
John Papa

This is really cool! Thanks for sharing

Collapse
 
priteshusadadiya profile image
Pritesh Usadadiya

This is super useful. Thanks Bryan

Collapse
 
andypiper profile image
Andy Piper

One additional step you'll need here is to make the development environment name configurable (or, edit index.js line 52 to match the name for the 30-day search environment you've created in the Twitter Developer portal). You could actually simplify the auth code here too, since Bearer Token only auth will work for the premium APIs; tweet_mode=extended should also not be needed, since the premium APIs should return full Tweets by default. I'll have a play :-) Thanks for sharing!

Collapse
 
nebrius profile image
Bryan Hughes

Good call on making the environment configurable, I just pushed a change with that.

As for redoing the auth flow, I'd be happy to look at a PR from someone else who reworkds. I'm done with the project I needed this tool for, and I'm kinda swamped the next few weeks.