This week’s assignment was to create a bot. I wanted to create a bot that serves to a meaningful purpose so I created a twitter bot that searches for recent global warming hash tags and grabs that tweet and retweet them on bot’s account once an hour to create global awareness.
I used Twitter api to create this bot application. In order the create the project I needed node.js. Here’s the link for twitter developper API referance page for search tweets. Reference Page
In the twitter developper platform, I’ve reached the parameters where I’m gonna provide into my objects.
The q was for what I need for actually search for the hash tag which is ‘#globalwarming’ and the result type was what I needed to access like next, popular or recent tweets. I preferred to search for recent tweets because of my purpose was to create awareness on recent global warming related events. Count was another parameter I needed to count how many tweets I need to grab which I grab just one to not over crowed.
Than I needed to get request in order to get the latest tweets. To do it I’ve used get() method, which needs the path that you I need to submit to the actual twitter API path, the parameters and a callback holding an error and a response with the fetch data from the Twitter database.
Data statuses is the array that holds the tweets that I grabbed from Twitter database which I only have one count.
To retweet I needed to make post request to the server. I used “tweet.id_str” for id. And the request itself is actually doing everything for you all I needed to return() it. And I put all of them in retweet function to call.
Last thing I did was to setInterval() to run the retweet function every hour.
Here some tweet I got;