Posts tagged ‘twitter auto tweet script’

Lately I was wanting to create a scheduled tweet to post to youtube. I then researched into twitter’s api and found that it needed cURL fields, so I produced the following script.

<?
$twitterUsername = Username;
$twitterPassword = password;
$status = "What you want the tweet to say here. This can include links.";
	if ($status) {
		$tweetUrl = 'http://www.twitter.com/statuses/update.xml';
 
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "$tweetUrl");
		curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status");
		curl_setopt($curl, CURLOPT_USERPWD, "$twitterUsername:$twitterPassword");
 
		$result = curl_exec($curl);
		$resultArray = curl_getinfo($curl);
 
		if ($resultArray['http_code'] == 200) {
			return true;
		} else {
			return false;
		}
 
 
		curl_close($curl);
	}
?>

You are free to use and modify this script or set it up as a cron. If you use it as a cron make sure to add a time variable. Thank you for using bright-tutorials.