May 2013

Automate your twitter posts with views bulk operations, twitter module, and rules scheduler

Have you ever wanted to make your Drupal site tweet about random stuff? I did and I need to do it for an upcoming project. It's really not too difficult to accomplish this task with views bulk operations, the twitter module, and rules scheduler.

Required modules

Setting up your VBO View

The first thing you need to do is create a view that provides the list of nodes we want to tweet about but doesn't have a Page or Block display. We're only going to be using this view to provide data to rules scheduler.

Then you need to add a Bulk operations: Content field to the view and some filter criteria.

Creating the Rules Component

After you save your view you go to the Rules then Components page and click "Add new component" link on the top of the page. Select Action set as the Component plugin then click continue. After that give it a name and tags, we won't need to use variables.

After that you can start setting up your rules. Rule components (Action set) are like rules but they do not have any Events associated with the rule, that's where the Rules Scheduler module comes in. First we're going to need to setup our action to load the data from the views bulk operations view we created earlier. Select the 'Load a list of entity objects from a VBO View." under the dropdown.

Next select the View and Display you want to use for this Component, you can also send arguments to your view that supports tokens. You can also change the Variable label and Variable name for the results of the view if you want to.

After that you need to add a loop action to the Component that will loop threw the results of the view.

Then inside that loop we need to add an action, we're going to use the "Post message to Twitter" action from the Twitter module.

After that we need to setup the message, you can use token to create this and select the Sender account you want to tweet from.

After that we need to add one more action to the Component. We're going to create an action for the Rules Scheduler to "Schedule component evaluation", which basically means run the rule and schedule to run it in N number of minutes/seconds/hours/etc.

Then select the Component you want to use:

And finally schedule the evaluation date, you can do this with a fixed time or use a format that the strtotime() function can consume.

You should end up with something that looks like this:

After that you can execute the Component from the Components page:

The end result

After it runs for the first time you should see an entry on the Schedule page for it and it should have tweeted.

You may have to adjust your cron settings to make this work properly, the rule is only triggered when cron runs.