ScheduledTweets: Free And Fully Ajaxed PHP Application To Schedule Tweets

Almost every Twitter user needs the ability of scheduling tweets. There may be a tweet that you need to send later or you may want to Tweet 7/24 but you must sleep as well :).

Although there are web based services which enable you to schedule tweeting, you may not want to give your Twitter password.

Here comes ScheduledTweets. It is a 100% free web application to schedule your tweets that you can install into your web hosting account.

ScheduledTweetsDownload

ScheduledTweets is built with PHP, uses MySQL to store the data & its interface is fully Ajaxed.

It enables you to define time-intervals which your tweets will be sent every x minutes. You can enter unlimited tweets, drag'n drop your tweets to change the order they will be sent.

Also, URL shortening service TinyURL is integrated for shorter tweets.

ScheduledTweets comes with a web-based friendly installer that helps you define database & Twitter information easily.

Why To Use ScheduledTweets?

Twitter is both an instant messaging & a micro-blogging platform. You will probably not schedule your personal tweets (I won't, as it clearly becomes meaningless) but if you are regularly sharing stuff on a subject (like I do), then it has the same benefit as scheduling a post on a blog.

How To Use?

Once you are logged in,

  • Add tweets to the queue (you can drag'n drop order them)
  • Add schedules like: on Mondays, between 10:00 to 16:00 tweet every 60 minutes .Schedules are not that smart -currently- & you can define crossing schedules.

How To Install (Automated)?

  • Create a MySQL database & user
  • After downloading it, unzip the files to a folder & upload them to your hosting account
  • Run http://www.yourdomainname.com/scheduled-tweets-url/index.php
  • Define the MySQL database information you created in the first step. Also define your Twitter info and desired ScheduledTweets admin info
  • Click install
  • Setup a cron job to http://www.yourdomainname.com/inc/functions.php?getAction=cronTweet (the interval must be lower than your smallest interval defined in ScheduledTweets)
  • Click "Start ScheduledTweets" button at the top menu
  • That's it

How To Install (Manual)?

  • Create a MySQL database & user
  • After downloading it, unzip the files to a folder & upload them to your hosting account
  • Run setup.sql (inc/setup/setup.sql) on your database
  • Edit the options in inc/config.php (database info, Twitter info, scheduledTweets info)
  • Setup a cron job to http://www.yourdomainname.com/inc/functions.php?getAction=cronTweet (the interval must be lower than your smallest interval defined in ScheduledTweets)
  • Click "Start ScheduledTweets" button at the top menu
  • That's it

How To Setup Cron Jobs:

If your hosting provider does not enable you to setup cron jobs than you can use these free web services as well:

Else:

Roadmap:

  • Multiple Twitter accounts support
  • Multiple URL shortening services support
  • Displaying tweets sent previously
  • Disable crossing schedules

License:

ScheduledTweets is free to use for both personal & commercial projects. But it can not be sold or re-distributed in anyway.

Thanks to:

P.S. I'm more a Microsoft scripting languages guy (sorry :)), wanted to dive into PHP & this project is the longest code I've written with PHP. So, I'll be glad to hear any improvements.

Update (20 April 2009):

V1.1

  • inc>functions.php is updated to fix the non-functioning start-stop button.
  • Phil

    Umut, that looks awesome. Can’t believe that you give this for free.

    I will try this today 🙂

    Keep up the great work. Love WRD.

  • Thank you for sharing this tutorial to us.

    i will try today.

    thank you again.

  • Wow…it’s really usefull. Thanks to share with us 🙂

  • Umut, very good job. Thanks for giving away it. I will try to make some improvements 😉

  • @Phil, @Adrian, @jangkrikjr,

    Great to hear that it looks good on your side. I had fun while creating it.

    @HMERT,

    Thanks very much for the support 🙂 .

  • Jamal

    Hi,

    Great work, only yesterday I was searching for similar tweeting function, happy to have it delivered for free today :-).

    I am trying to import my feeds and schedule them, and add some function like edit tweet in q.

    Thanks

  • Can’t get it to work once installed 🙁

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘milest_milest’@’localhost’ (using password: YES) in /home/milest/public_html/newfollowing.com/scheduler/inc/config.php on line 12
    Error connecting to mysql

  • @Miles,
    For some reason it can not connect to your MySQL server.

    Can you check the inc/config.php and make sure all your connection, ScheduledTweets and Twitter setting are written there. If not, then please manually mention them as there maight have been a write error in the installation.

  • Nice! Thanks – this is perfect!!!!

  • a bug, you cannot add tweets with an apostrophy 🙂

  • I am not able to get the cron job working…otherwise, this is awesome.

  • @TheAnand,

    Make sure system is started. Check the top menu of the application. There is a start-stop button there.

    And, you can use http://www.setcronjob.com/ to setup a cron job.

  • Nice. I just installed it. FYI… if the tweet has an ampersand it truncates before it.

  • @TheAnand & @David,

    There is an input filter/protection that clears some types of inputs. I’ll be fixing the ampersand problem & upload the new version in a few days.

  • Hi,
    This works great and thanks for developing and making this public. I noticed that today it was not posting my tweets and started to step through the code, at which point I found the if clause that was holding it up. On line ~256(give or take, I added some debug statements) in functions.php, there is this condition:

    if (date(“H:i:s”, mktime()-($scheduleInterval*60)) >= $lastTweetTime)

    which basically was returning false the whole time during my interval(9-17) because the time of my last tweet was 15:39(lastTweetTime), yet all the times being returned via date() were before that time.

    When I deleted that tweet from the DB(it was the only tweet there), everything worked fine. I am doing 9-17:00 intervals, so I imagine I will have this problem again tomorrow morning.

    unless there is something that I am blatantly overlooking, which is very probable!

    Feel free to email me to talk about this.

  • Update:
    So I fixed my issue adding a second condition to that if statement as follows:
    if ((date(“H:i:s”, mktime()-($scheduleInterval*60)) >= $lastTweetTime)||($tweetSentDate < date(“Y:m:d”)))

    where $tweetSentDate is:
    $tweetSentDate = $row[‘tweetSentDate’];

  • Uggh, one more update. It occurred to me today that the original mysql query that grabbed the row which directly affects the if statements in my previous comments(see above) did not work properly with mySQL. Instead, the tatement I had to use was this:
    SELECT * FROM tweets WHERE tweetStatus = 1 ORDER BY tweetSentDate DESC, tweetSentTime DESC LIMIT 1

    the difference being “…tweetSentDate DESC, tweetSentTime DESC” instead of “…tweetSentDate, tweetSentTime DESC”

  • @Steve,

    Thanks very much for the updates.

    I couldn’t find a time to dive into the code but will be checking the problems you mentioned and adding the fixes today.

  • I installed the script,,, fine,
    ran a cron,
    … doesn’t work.

    Is there an update?

  • Maggie

    Thanks Umut M. for your work! I don’t understand the update scheme. It’s either me or a bug …

    The cron triggers your script every 57th minute of every hour.

    scheduleStartTime 01:55
    scheduleEndTime 18:05

    With the scheduleInterval at 165, I get only 2 tweets per day, at:
    01:57
    02:00

    That’s it. Same setting, but a higher interval results in *more* tweets:

    scheduleInterval at 330.
    01:57
    02:00
    02:57
    03:00

    ???

    Is this related to Steve Krzysiak suggestions, or something else?

    Thanks anyway!

  • Jim

    Does this allow oathetication through twitter for other users to be able to schedule their tweets? Or is this pure database/configuration file for one account only.

  • @Jim,

    It is only for 1 user. On th other hand with some modification, it can easily be converted to a multi-Twitter-user application.

  • Maya Janis

    @steve Thanks for your update. Suddenly the software seems to work again. Thanks for the code x 2.

  • @Maya Glad my code helped someone, for awhile I thought I was rambling!

  • George

    Crons won’t work can somebody point to a bug free update or some guidance?

  • George

    @Steve Krzysiak can you post an up to date file that gets this cute little script working?

  • Just FYI, I have updated the script but just couldn’t polish it. I’ll certainly be uploading the “fixed” version this week & anybody can download.

  • George

    Thanks for the heads up Umut.I’m head over heels for the updated version, thanks.

  • pico

    tierd this it won’t work any other alternative?

  • So I subscribed to the rss feed, and I did not see how to download the application. How do I do this?

  • @Spence,

    While reading the latest post from a RSS reader, you can see the link at the bottom of the post under the title: “special downloads”.

  • Very nice script! I have made a few modifications to the script and all is running very well.

    One thing you will need to add, though, is: $status = urlencode($status); in your sendTweet function as you have to URL encode any data sent to twitter via the API.

    Thanks

  • Mine just doesn’t work, please help!

  • Mike Jones

    is scheduledTweets open source so that we can update it to fit application within our own site.

  • Bubba42

    The application has stopped working after only a day. I’ve even waited a day and hit the cron link myself, but it won’t work. Is there any further development on this?

  • @Mike,
    Yes, it is open source & you can use it almost however you want. Just, can not re-sell or distribute it.

    @Bubba42,
    There is still development. I have fixed some bugs but just couldn’t polish it. I’m willing to make it online for a while but just couldn’t create the time. Will try to do it this week.

  • Jay

    any news on the updated fixes?

  • @Jay,

    This was probably my worst planning on a project.

    I have the app working here but couldn’t update few thing & share.

    Ok, promise, I’ll be rolling the update next week no matter what :).

  • Any updates? Mine still will not work.

  • @Andrew,

    Like mentioned above, I’ll be rolling an update this week. Around Wednesday or Thursday I think.

  • I cant get it to work probably. i works when , logged in and reload within the timeframe i made. (16.00 – 16.25 every 20 minutes) just want it to do one tweed every day.

    The cron job is from (http://www.setcronjob.com/) since my webhost aint supporting cron job.

    Is there a way to test if the cron job is actually working, correct?

    many thank for the code

  • Broken

    This is a total shame, godaddy.com set cron job and the script just sits idle, I get thrown out of Twitter but no Tweets to show for, just too many connection that were supposedly made.
    Why not give a step by step clear explanation of how to set it up correctly?
    Thanks for nothing!

  • @Broken,

    It may have some problems, bugs for sure.

    However, there is a step-by-step tutorial, don’t know what else to mention in the steps as there are no less & more steps.

    And, you may have realized already that it is not a commercial script, it is free and open source. So that other users, like you, can improve/fix what I have done missing/wrong and share a better code.

  • Hi Umut,

    Don’t know if you were aware, but there’s another Cron service (http://cronless.com) that also can help out here, too. If you’re tweeting once a day (or even twice), the jobs are FREE for life, unlike the other two services. 🙂

    Enjoy,
    -Dave

  • Hi Umut.

    Anyone you know of who has added Bit.ly…

    Also, your roadmap is looking a little like you’re never going to get there… since this app has been around since April.

    I’d love to see Bit.ly support, and am sure I could sort it out myself, but just wondering. Lazy as I am!

    Alister (@alicam)

  • @Alister,
    You’re right with that. I have some updates on my side but just couldn’t create the time for cleaning the code and uploading them.

    For bit.ly, although I don’t know if anyone is implemented that, you can Google a bit.ly php function and replace that on the code.

  • Thank you @SteveKrzysiak for the updated functions.php
    I posted for download on my server everyone is welcomed to it: http://www.zachschneider.com/downloads/functions.php-NEW

  • Soso Jana

    hey body… how to download it.
    After subscribe what to do … i didn’t see any link or something in email or google reader

  • @Soso,

    In your RSS reader, check the latest WRD post:
    You’ll find “special downloads” at the bottom of the post.

  • Very useful information. Thanks I will be taking this apart and making it into a cron. The source code will be available at http://bright-tutorials.com if anyone wants it.

    Thanks!

  • Danny

    Thanks for this. One question – what should the ‘command’ be for the cron job?

  • David

    Thanks Umut! I was preparing to write a similar script but decided to see what might be available first. Much appreciated.

    Thanks also to Steve for bug-fix suggestions.

    I modified functions.php in a couple of ways that others might find helpful (and probably won’t stop there)…

    ***

    1: My error_log was filling up faster than I could keep track of it because of the lack of parameters usualy being sent and the interval of the cron job. I added this function and changed the variable assignment accordingly. Note that I commented out the use of the myfilter class, figuring that if I’m the only one adding the tweets that I could know to be careful about using tags and such.

    function setVar ($varName) {

    if (!empty($_POST[$varName])) {
    $checkValue = $_POST[$varName];
    } else {
    if (!empty($_GET[$varName])) $checkValue = $_GET[$varName];
    else $checkValue = ”;
    }

    return $checkValue;

    }

    $installDBName = setVar(‘installDBName’);
    $installDBUser = setVar(‘installDBUser’);
    $installDBPass = setVar(‘installDBPass’);
    $installDBHost = setVar(‘installDBHost’);
    etc., etc. [make sure to catch them all–there’s one GET and the rest are POST]

    ***

    2) I also quoted the ‘w’ in this section of code (in 3 places) to eliminate those error_log entries:

    if (date(‘w’) == 0) {
    $dayToUse = date(‘w’) + 1;
    } else {
    $dayToUse = date(‘w’);
    }

    ***

    3) In the >> if ($action == “newTweet”){ <> $query = “INSERT INTO tweets… <<, I added:

    $tweetDetails = str_replace(chr(10),'',$tweetDetails);
    $tweetDetails = str_replace(chr(13),'',$tweetDetails);
    $tweetDetails = mysql_real_escape_string($tweetDetails);

    This removes carriage returns and newlines that might inadvertently get put into the tweet, and also properly escapes various characters appropriate for insertion in mySQL such as quotation marks, apostrophes and backslashes (see php.net/mysqlreal_escape_string)

    ***

    4) A minor change but worth considering:

    The text "Error, insert query failed" appears in six places in the code and "Error, update query failed" appears in three. I numbered them so I'd be able to tell where a problem was occuring (i.e. failed #1..#6,failed #1..#3).

    ***

    Hope this proves to be helpful for others.

    David

  • David

    How ironic. I said I could be careful about using tags, and then in my post I used symbols that didn’t translate well :-).

    Number 3 should read…

    3) In the section [-= if ($action == “newTweet”){ =-] just before [-= $query = “INSERT INTO tweets… =-] I added:

    David

  • David

    A few other things of note:

    1) As James West points out, add “$status = urlencode($status);” near the beginning of the if statements (such as under the “$tweetUrl = …” statement.

    2) The script does exactly what it’s supposed to. Unless you are encountering a technical issue (i.e. connection issue with mySQL database), you may be expecting something different of it. For example, tweets go out at the interval scheduled, during the days and times entered (don’t miss this step), and when Scheduled Tweets is “started” but not when it is “stopped”. Each tweet you enter will only ever get tweeted once (tweetStatus flag), so if you enter three tweets and have an interval of 5 minutes–and you don’t enter more tweets–cron will continue running the job but you won’t see anything new after about 15 minutes. As written, it doesn’t loop and the same tweets aren’t then tweeted the next day.

    3) FYI, I’m not the David or Dave who posted _prior_ to today.

    Best,

    David

  • @David,

    What you’re doing is great.

    Scheduled Tweets is 95% complete but had that 5% problems which was causing problems. I did some updates locally but couldn’t find time complete & organize them.

    It’ll be great that you post any updates you make, I’ll be watching them and once you’re ok, I’ll update the download.

    Again, thanks so much, this is why I love open source :).

  • David

    Umut,

    Many thanks. I know the feeling all too well of not getting the last 5% done :-)!

    I had thought about this before but didn’t give it much attention. The $dayToUse = date(‘w’) + 1 (when == 0 ) isn’t right. You’re using 1-7 for Monday through Sunday, so that would theoretically duplicate Monday’s schedule twice.

    Although, and I’m far too tired right now to delve into it, that’s not what happened. Instead, I noticed that after midnight on Saturday (thus, on Sunday) tweets began sending at the cron-job interval (in my case, 5 minutes) rather than at any interval listed in the ‘schedules’ table (all greater than 10 minutes).

    I’ve changed:

    =====
    if (date(‘w’) == 0) {
    $dayToUse = date(‘w’) + 1;
    } else {
    $dayToUse = date(‘w’);
    }
    =====

    to:

    =====
    if (date(‘w’) == 0) {
    $dayToUse= ‘7’;
    } else {
    $dayToUse = date(‘w’);
    }

    =====

    And now I’m going to get some much-needed sleep. 😉

    Best,

    David

  • David

    Umut,

    Incidentally, you mention that there were some known problems. Are you aware of anything else that hasn’t been touched on in these comments?

    Definitely three cheers for open source!

    David

  • rathin

    Great DEMO.. really It appreciate me …

  • Hello,

    i like this software, but twitter has changed now to oauth only. Will you change the software also?

    Best,
    Karl

  • @Karl,

    I’d love to update it but can’t find the time for that right now.

    If any users update it, please let me know and I’ll be happy to update the files with the new ones.

  • Wouldn’t it be nice if I was able to update this script to use oAuth? That would be the second of your free downloads that I provided a key upgrade to. Interesting… Need to find time to do this.

  • @giles,

    That would be awesome again 🙂

  • mark

    If anyone has updated this to use Oauth and is willing to share please let me know.
    Mark

  • tried everything and it al seems to work except for one thing…. i don’t see any new tweets appearing my twitter page. I even setup the cron jobs and everything…. and i set cron jobs all the time so it’s not that.

  • @John,

    Twitter removed the standard authentication method it provides and now only supports oAuth which ScheduledTweets currently doesn’t support.

  • Mahmood

    I can’t believe i spend my weekend on this thing trying to make it work, it look great and handy. thanks to the creator.

    did anyone figured out how it will work with the new twitter authintication?

  • Mahmood

    Hi there,
    I changed the script to include the new (oAuth), I’m able to post to twitter now but only the first msg in line, it doesn’t move to the next msg somehow.

    I will try to fix this if i could, if anyone have any advice please contact me. I will share the package once its fully functioning.

    thanks again to the creator 😉

  • Mahmood

    @Umut, thanks for ignoring me here and on twitter, got everything sort out, its a great script so i have to say thanks again for sharing it.

  • @Mahmood,

    I haven’t seen the twitter message, sorry for that.

    After not touching the ScheduledTweets code for the last year, I was expecting that the community could answer your questions (which you seem to have asked to them as well).

    Anyways, great to hear that everything is sorted out.

  • N

    Nice script, it doesn’t work out of the box but if you understand PHP a little it’s not difficult to get it working again.
    To make it work I used https://github.com/themattharris/tmhOAuth this one, but there are other scripts/classes as well.

  • Dave

    Does anyone have an up-to-date version of this script that works and is compatible with the new twitter OAuth lib? I can shoot you some cash for it – it’s required for a project.

    Cheers,
    Dave

  • Really nice web app , it can easily compete bufferapp with some extra modifications and addons our team has started development on it .. 🙂

  • Sam Tuke

    Any chance of changing the license so I can work on it?

    Please please please switch to AGPL or similar so this app is useful again!

Search