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.

2 Comments

  1. Marcel says:

    Hey,

    Do you know, how to change the name ‘from’ ?
    Twitter currently displays now ‘from twitter api’

    How to set ‘from marcelpronk.eu’ as example

    TNX! hope you can help me

  2. Austin says:

    Sorry, but currently the only way to do that is to get your application verified by twitter and then use oauth.

Leave a Reply