Twitter API Consulting

Free open source code for Twitter API Engagement Programming


// Copyright (c) 2013 Adam Green. All rights reserved.
// See for licensing of this code.

// Run this as a cronjob every minute

$db = new db();
$connection = get_connection();

// Load tweeting functions

// Get any tweets scheduled for the current day and time
$query = "SELECT id, tweet_text
	FROM autotweet_scheduled
	WHERE (tweet_date = date(now())
		AND tweet_hour = hour(now())
		AND tweet_minute = minute(now()))
	AND NOT posted";
$results = $db->select($query);
while ($row = mysqli_fetch_assoc($results)) {
	$id = $row['id'];
	$tweet_text = $row['tweet_text'];
	// Post this tweet
  	$http_code = post_tweet($tweet_text);

	// Flag it as having been posted
	// Even if the $http_code is not 200, this is still flagged as posted
	// It is safer to not try to repeat this posting to avoid duplication
	// Log this tweet
	$db->insert('autotweet_log',"tweet_type='text', scheduled=1, id=$id, tweet_text='$tweet_text', http_code=$http_code");


I'm a member of the #140dev Twitter development community - join us for free source code and tutorials: