<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TimeWaster's Place &#187; twitter</title>
	<atom:link href="http://www.timewaster.de/tag/twitter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.timewaster.de</link>
	<description>Programming, Design, Tekkie Stuff and more</description>
	<lastBuildDate>Wed, 04 Aug 2010 14:02:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Twitter made easy &#8211; How to tweet with PHP with 19 lines of code</title>
		<link>http://www.timewaster.de/twitter-made-easy-how-to-tweet-with-php-in-17-lines-of-code/</link>
		<comments>http://www.timewaster.de/twitter-made-easy-how-to-tweet-with-php-in-17-lines-of-code/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 20:38:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programmierung]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.timewaster.de/?p=185</guid>
		<description><![CDATA[You know the dilemma, you want to write a simple tweeting PHP script and have to mess around with the Twitter API.
With the following small script you can tweet with a simple function call. It IS that simple (And SSL secured!!!).
Here&#8217;s the function:
function tweet($user, $pass, $text) {
	unset($GLOBALS['tweetError']);
	if(strlen($text) > 140) { $GLOBALS['tweetError'] = 'TEXT TOO LONG: [...]]]></description>
			<content:encoded><![CDATA[<p>You know the dilemma, you want to write a simple tweeting PHP script and have to mess around with the Twitter API.<br />
With the following small script you can tweet with a simple function call. It IS that simple (And SSL secured!!!).</p>
<p>Here&#8217;s the function:</p>
<pre><code>function tweet($user, $pass, $text) {
	unset($GLOBALS['tweetError']);
	if(strlen($text) > 140) { $GLOBALS['tweetError'] = 'TEXT TOO LONG: '.$text; return false; }
	$tweet = curl_init();
	curl_setopt($tweet, CURLOPT_URL, 'https://www.twitter.com/statuses/update.xml');
	curl_setopt($tweet, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($tweet, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($tweet, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($user.':'.$pass)));
	curl_setopt($tweet, CURLOPT_POST, 1);
	curl_setopt($tweet, CURLOPT_POSTFIELDS, 'status='.utf8_encode($text));
	if(!$return = curl_exec($tweet)) $GLOBALS['tweetError'] = 'CURL ERROR: '.curl_error($tweet);
	else if($returnData = simplexml_load_string($return)) {
		if(!isSet($returnData->error)) $GLOBALS['tweetSuccess'] = 'Created at: '.$returnData->created_at.'Text: '.utf8_decode($returnData->text);
		else $GLOBALS['tweetError'] = 'TWITTER ERROR: '.$returnData->error;
	} else $GLOBALS['tweetError'] = 'RETURN IS NOT XML: '.$return;
	curl_close($tweet);
	return (isSet($GLOBALS['tweetError']))?false:true;
}</code></pre>
<p>To make a tweet just call the function:</p>
<pre><code>tweet("username", "password", "My cool tweet!");</code></pre>
<p>The function returns &#8220;true&#8221; if successful or &#8220;false&#8221; if not.<br />
To echo out the error or success messages, just use this code:</p>
<pre><code>if(tweet("username", "password", "My cool tweet!")) {
	echo 'Tweet Successful!'.$GLOBALS['tweetSuccess'];
} else {
	echo 'Tweet Error!'.$GLOBALS['tweetError'];
}</code></pre>
<p>If there was an error, the error description is saved in $GLOBALS['tweetError'], and if the tweet was successful, the time and the text itself is saved in $GLOBALS['tweetSuccess'].</p>
<p>Have fun and happy (automatic?) tweeting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.timewaster.de/twitter-made-easy-how-to-tweet-with-php-in-17-lines-of-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
