Social networking automation can be helpful. What if you wanted to schedule your Tweets? If you are implementing a strategy for Twitter, instead of worrying about the steady flow of your tweets, you can create a simple application to send pre-recorded (scheduled) tweets. Imagine a simple application as described in the use case diagram below:
Creating the Database
We can use PHP and MySQL to create a simple Twitter scheduler application to send your tweets. To create the application we will use the single database table (queue) to store your tweets. Here is how the ‘queue’ table will look like when created in MySQL:
+———+——–+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+———+——–+——+—–+———+—————-+
| id | int(6) | NO | PRI | NULL | auto_increment |
| message | text | NO | | NULL | |
| status | int(1) | NO | | 0 | |
+———+——–+——+—–+———+—————-+
The queue table will contain only the three fields ‘id’, ‘message’, and the ‘status’ field. The ‘id’ (integer) field auto-increments by default. The ‘message’ (text) field contains your tweets. The ‘status’ (integer) field indicates whether or not the tweet was sent. The status value of 0 indicates tweet ‘not sent’ condition. The status value of 1 indicates ‘tweet sent’ condition. The following fragment is the SQL fragment required to create the ‘queue’ table:
CREATE TABLE `mytest`.`queue` (
`id` INT( 6 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`message` TEXT NOT NULL ,
`status` INT( 1 ) NOT NULL DEFAULT ’0′
) ENGINE = MYISAM ;
With the database out of the way, we can create a simple HTML/PHP interface.
Building the Interface
All we need for our interface is a simple HTML form that submits (future) tweets to our MySQL database. It would also be nice to have a visible list of (future) tweets already stored in the database. Last and not the least, there should be a way to delete unwanted tweets. The following Figure shows the index.php when rendered in a web browser.

As you can see in the preceding figure, the index page is relatively simple. There is a database query that is always called (to show stored tweets) just below the new (tweet entry) form.
When you click on the ‘Add Future Tweet’ button, the form submits the new tweet to database returning you back to the same screen as your newly added tweet appears on the top of the (‘My Future Tweets’) list.
Sending the Tweets
We can send Twitter updates using the Twitter API. We can use PHP and curl to send our tweet using the http://twitter.com/statuses/update.xml link. The following code fragment (sendTweet.php) is used to send a single tweet.
<?php
include(“config.php”);
mysql_connect(localhost,$username,$password);
@@mysql_select_db($database) or die( “Unable to select my database”);
### get the tweet
$result = mysql_query(“select id, message from queue where status=0 order by id asc LIMIT 1″);
$row = mysql_fetch_array($result);
### send the tweet
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, “$tURL”);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
$message = $row['message'];
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, “status=$message”);
curl_setopt($curl_handle, CURLOPT_USERPWD, “$tusrid:$tpasswd”);
$response = curl_exec($curl_handle);
curl_close($curl_handle);
// get the status message
if (empty($response)) {
echo ‘tweet not delivered’;
} else {
echo ‘tweet delivered’;
###update db status
$mid = $row['id'];
mysql_query(“UPDATE queue SET status = 1 WHERE id = $mid”);
}
mysql_close();
?>
We use a POST request coupled with the user credentials necessary to handle the basic authentication used at http://twitter.com/statuses/update.xml. Note that this link is stored in an external configuration file and is referenced by $tURL variable.
Scheduling Your Tweets
The web part of the application does not submit the tweet(s). We leave that to a scheduled job. Now we come to the part that actually initiates the tweet uploads. On a Linux flavored environment you can use crontab to create your schedule.
Let’s suppose that you want to send 5 tweets per day at 7am, 9am, 11am, 1pm and 3pm. Executing crontab –e to edit your crontab list, enter the following:
# Tweet 5 times a day at 7am, 9am, 11am, 1pm and 3pm
* 8,10,12,14,16 * * * php sendTweet.php
Note that you can also send tweets manually by using the same command (php sendTweet.php). in your shell window.
Extending Your Application
The application we have built can be extended to do many more things. You can add custom authentication, the workflow approval process, RSS integration, etc.
Click here to Download the entire Twitter Scheduler Code.
Enjoy!
Tags: schedule tweets, SMO, social media strategy, tweets, twitter
Categories
Archive
- February 2011
- January 2011
- December 2010
- October 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- May 2008
Links
- Brass Name
- CMS Matrix
- Mashable
- Matt Cutts Blog
- Membership Plugin
- s2Member.com
- SEO Text Browser
- WordPress Themes
Meta
Important Articles
Recent Articles
Latest Comments
- Comment on Step-by-step Mac Tutorial for rankingfactors.pl by JohnHi Neil, May want to check these links: https://bbs.archlinux.org/viewtopic.php?pid=715402 http://stackoverflow.com/questions/2279414/why-does-my-perl-program-complain-cant-locate-uri-pm-in-inc http://www.perlmonks.org/?node_id=280985 http://ubuntuforums.org/archive/index.php/t-1279901.html Also just by looking at your errors, it seems as if either LWP is no […]
- Comment on Step-by-step Mac Tutorial for rankingfactors.pl by neilgeeHi John, I am getting the same error as "nkraf" above. When running the script originally I get the "Can't locate LWP/Simple.pm " So I copied the LWP directory and filed it in both /perl5/site_perl/5.10.1 and /perl5/5.10.1 but now when i run the script I get: "BEGIN failed--compilation aborted at /Applications/XAMPP/xamppfiles/l […]
- Comment on A Step-by-step Tutorial for rankingfactors.pl Script by JohnHi, You may want to check this link: http://www.tek-tips.com/viewthread.cfm?qid=1424638&page=15 I'll have a look when I get a chance. Thanks, John […]
- Comment on A Step-by-step Tutorial for rankingfactors.pl Script by EpicVisionI'm on Windows 7 IIS 7.5 and have the same error: Starting.. ..cleanup done ..getting SERPs ..got the SERPs ..got the real titles ..finished partial title comparisons Quantifier follows nothing in regex; marked by […]
- Comment on A Step-by-step Tutorial for rankingfactors.pl Script by JohnHello, Please make sure your Internet connection is good and that your file permissions are sufficient. Thanks, John […]
- Comment on A Step-by-step Tutorial for rankingfactors.pl Script by JohnHello, I have not tested any scripts on Baidu (that are included for the book). I am sure it would easy to make modifications for Baidu. Thanks, John […]
- Comment on Social Media Optimization and its Relationship to SEO by FritzSeems like Google has made some major changes at the beginning of the year in regards to "dead" social profiles and has stepped up the quality control quite a bit (I have noticed this with my pages and also pages from friends) […]
- Comment on Social Media Optimization and its Relationship to SEO by Tweets that mention Social Media Optimization and its Relationship to SEO « SEO Warrior -- Topsy.com[...] This post was mentioned on Twitter by Ashley Spilak, SMO Scout. SMO Scout said: Blog: Social Media Optimization and its Relationship to SEO « SEO Warrior http://bit.ly/gBuwj8 […]
- Comment on Social Media Optimization and its Relationship to SEO by BlogFull.orgSEO for Google News... Published on February 19, 2011 by Last Click News · No CommentsOnline companies that want to strengthen their search engine optimization (SEO) campaigns can benefit from ranking on Google News.With so many SEO campaigns competing for the same ...... […]
- Comment on New SEO Warrior Code Release on Target for January 15th, 2010 by hexingchapter-2 => spiderviewer.php => line 48 , the code is : $originalHTML=preg_replace('/&[#]{0,1}.[^ ]*;/sim',' ',$originalHTML); should be : $originalHTML=preg_replace('/&[#]{0,1}.[^ ]*?;/sim',' ',$originalHTML); […]