How to automate a request to get all tweets of an hashtag

Hi @osemele! Welcome to the Postman community! :trophy:

Funny you should ask this question, as I did something quite similar very recently! I created a collection to search for a specific hashtag for our virtual conference, Postman Galaxy. You can check out and fork the collection here!

The basic gist of the collection is that it searches for a hashtag in the query field like this: %23ENDSARS. It was designed to run on a monitor every 5 minutes to pull in the most recent batch of tweets with the hashtag I was searching for. It tracks the id of the most recent tweet each time it runs, and on each ensuing run, it only searches for tweets that have an id that is newer than the id that was tracked. This ensures you’re only getting the freshest tweets every 5 minutes.

To go back and capture the older tweets, this can be done by taking advantage of the postman.setNextRequest method and calling the same “Search for Tweets” request multiple times. This must be done by also capturing and using the next_token returned by the Twitter API. You could create an array as an environment variable and every time the “Search for tweets” request is run, it adds the new found tweets to the array and continues to do so each time the collection is run. I actually talk a bit about something similar in this post here!

I would recommend forking the collection I linked to in the beginning of this post and see if that helps you get started. The collection will help you stay up to date with new and current tweets, the older forum post I wrote should help you go back and programmatically get all of the historical tweets. If you run into issues or have further questions, feel free to post here again :slight_smile:

2 Likes