Mass Tweet Your Followers With Node.js

This tutorial quickly describes how to use the Node Twitter API to mass tweet all of your followers at once. Even if you're not familiar with Node.js or javascript development, this article will tell you everything you need to know to easily mass tweet your followers individually.

Download & Install Dependencies

We will be using Node.js to write our script so be sure to download the latest stable version of Node if you don't already have it. Create an empty directory and run:

npm init

You will be asked a series of prompts. We recommend sticking with the defaults for now, but feel free to set up your project as you see fit. When the initializer finishes running, run:

npm install twitter --save

This will download the twitter api module and allow us to interact with the Twitter REST API.

Get Twitter Oauth Credentials

To use the twitter API, we will need to register our app with Twitter. Go to dev.twitter.com and register an app with your twitter account.

Once you've completed the app creation process, you will be given four important things...

  • consumer key
  • consumer secret
  • access token key
  • access token secret

Make sure you have these four values before continuing.

Create Node.js Twitter Script

Now that we have all the necessary dependencies installed in our project directory we can write the actual script that will mass tweet our followers individually. In the root directory of your project, create a file market.js.

var Twitter = require('twitter');

var client = new Twitter({
consumer_key: 'YOUR CONSUMER KEY',
consumer_secret: 'YOUR CONSUMER SECRET',
access_token_key: 'YOUR ACCESS TOKEN KEY',
access_token_secret: 'YOUR ACCESS TOKEN SECRET'
});

var params = {screen_name: 'your screen name', count:100};
client.get('/followers/list', params, function(error, tweets, response) {
if(!error) {
for(var i = 0; i < tweets.users.length; i++){
status = ' @' + tweets.users[i].screen_name + ' ..check this out!'
client.post('statuses/update', {status: status}, function(error, tweet, response) {
if(error) throw error;
console.log(response);
});
}
}
});

First, we initialize an instance of the twitter API module. Then we plug in our twitter credentials from our registered twitter app. Then we iterate through our followers and tweet a message @ their user name.

Running The Script

Now that we have our market.js ready to go, simply run the following from the command line:

node market.js

If all goes according to plan, you will successfully mass tweet your followers.

Rate Limits

Sure, twitter has rate limits for hitting their API. This script will allow you to tweet up to the limit depending on how many followers you have. It's important to note the count parameter, which in our example is set to 100. The Twitter REST API works off a paginated return system, allowing for a maximum of 200 followers to be returned per page. For more information on working with paginated results, check out the Twitter REST API.

Conclusion

This is a basic example of how you can use Node.js to mass tweet your followers. By iterating through each follower and constructing a message that includes their @screenname, this script effectively tweets a custom message targeting each one of your followers individually.

Your thoughts?