PHP Tweets for Twitter

If you want to tweet on your twitter account through your website, using PHP, then you have come to the right place.

Auto Tweets Through Websites or Blogs

If you want your website’s users comments to be tweeted on twitter automatically, or any other web activity related to posts, comments etc., then you can simply embed the following code on your website, which will be called right after your desired activity, which you want to be posted on twitter.

PHP Auto Tweets

$twitter_username = 'your_twitter_username';
$twitter_pwd = 'your_twitter_password';
$msg = "Testing Tweet from PHP by http://www.webtechquery.com";
	if ($msg) {
		$twitter_url = 'http://www.twitter.com/statuses/update.xml';

		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, "$twitter_url");
		curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$msg");
		curl_setopt($curl, CURLOPT_USERPWD, "$twitter_username:$twitter_pwd");

		$result = curl_exec($curl);
		$resultArray = curl_getinfo($curl);

		if ($resultArray['http_code'] == 200) {
			return true;
		} else {
			return false;
		}

		curl_close($curl);
	}

In the code, simply replace your_twitter_username and your_twitter_password with your twitter account’s username and password, and change the text of message Testing Tweet from PHP by http://www.webtechquery.com with your tweet message i.e. users comments, posts or anything else you want. After successful integration of this code with your website, you will be able to see your auto tweets on twitter.

Uncategorised

Leave a Reply

Your email address will not be published. Required fields are marked *