<?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>tech stuff &#187; html</title>
	<atom:link href="http://codytaylor.org/tag/html/feed" rel="self" type="application/rss+xml" />
	<link>http://codytaylor.org</link>
	<description>From Cody Taylor.</description>
	<lastBuildDate>Sun, 30 Oct 2011 04:15:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Update Twitter using Command Line, Javascript, Or PHP.</title>
		<link>http://codytaylor.org/2009/06/update-twitter-using-command-line-javascript-or-php.html</link>
		<comments>http://codytaylor.org/2009/06/update-twitter-using-command-line-javascript-or-php.html#comments</comments>
		<pubDate>Tue, 23 Jun 2009 02:13:09 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[status]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14162</guid>
		<description><![CDATA[Everyone seems to be all about twitter so here's some simple examples of how to integrate twitter...]]></description>
			<content:encoded><![CDATA[<p>Everyone seems to be all about Twitter so here&#8217;s some simple examples of how to update your Twitter status from a command line prompt, web server or simple html web site. These three examples require curl so install it if you don&#8217;t already have it. For these examples I&#8217;ll be using my Twitter user name &#8216;codytaylor1234&#8242;. My password is not &#8216;mypassword&#8217; so make sure you put in your own information.</p>
<p>The easiest way to update your Twitter account is to just call curl from the command line with this command.<br />
<pre><code>
curl --basic --user &quot;codytaylor1234:mypassword&quot; --data-ascii 
&quot;status=This Twitter update brought to you by curl on the command line&quot; 
&quot;http://twitter.com/statuses/update.json&quot;
</code></pre><br />
<br />
To update your Twitter status with PHP you are going to want to do the same sort of thing but with a bit more typing.<br />
<pre><code>
&lt;?php
$username = &#039;codytaylor1234&#039;;
$password = &#039;mypassword&#039;;

$update = &#039;This Twitter update is from a php script using curl&#039;;

$url = &#039;http://twitter.com/statuses/update.json&#039;;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, &quot;$url&quot;);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, &quot;status=&quot;.$update);
curl_setopt($ch, CURLOPT_USERPWD, $username.&quot;:&quot;.$password);
$result = curl_exec($ch);
curl_close($ch);

if($result)
&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;success&#039;;

?&gt;;
</code></pre></p>
<p>Since a cross-domain request in Javascript isn&#8217;t really an option we have to create a proxy using PHP in order to authenticate the user on the Twitter API. If anyone knows an easy way authenticate a Twitter user using only javascript I&#8217;d love to hear it. Anyway if we replace a small amount of code in the above example and put it in a file then we can use a simple ajax request to update our Twitter status. So the new PHP file would be:<br />
<pre><code>
&lt;?php
$username = $_POST[&#039;username&#039;];
$password = $_POST[&#039;password&#039;];

$update = $_POST[&#039;update&#039;];

$url = &#039;http://twitter.com/statuses/update.json&#039;;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, &quot;$url&quot;);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, &quot;status=&quot;.$update);
curl_setopt($ch, CURLOPT_USERPWD, $username.&quot;:&quot;.$password);
$result = curl_exec($ch);
curl_close($ch);

?&gt;
</code></pre></p>
<p>For this example I called that php file &#8216;twitter-update.php&#8217;. Now that we have our simple proxy we can update our twitter status with a simple html form and a little ajax. I used the prototype framework for my javascript.<br />
<pre><code>
&lt;script src=&quot;includes/prototype.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;script type=&#039;text/javascript&#039;&gt;
function update_twitter()
{
&nbsp;&nbsp;var param_string = &quot;username=&quot;+$(&#039;username&#039;).value+&quot;&amp;password=&quot;+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(&#039;password&#039;).value+&quot;&amp;update=&quot;+$(&#039;update&#039;).value;
&nbsp;&nbsp;alert(param_string);
&nbsp;&nbsp;var options = {
&nbsp;&nbsp;&nbsp;&nbsp;method: &quot;post&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;parameters: param_string,
&nbsp;&nbsp;&nbsp;&nbsp;onSuccess: function (xhr, Json) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Response received successfully.&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;onFailure: function (xhr, Json) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Request was unsuccessful.&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;};
&nbsp;&nbsp;
&nbsp;&nbsp;var oRequest = new Ajax.Request(&quot;twitter-update.php&quot;, options);
}

&lt;/script&gt;
</code></pre></p>
<p>Obviously this is for example purposes only and if you&#8217;re actually using it for production then you should edit it a lot. Now for the last little bit here&#8217;s the simple html form that starts it all.<br />
<pre><code>
User Name : &lt;input type=&#039;text&#039; id=&#039;username&#039; value=&#039;codytaylor1234&#039;&gt;&lt;br&gt;
Password&nbsp;&nbsp;: &lt;input type=&#039;password&#039; id=&#039;password&#039; value=&#039;mypassword&#039;&gt;&lt;br&gt;
New Status : &lt;input type=&#039;text&#039; id=&#039;update&#039; 
value=&#039;Twitter Update from html/javascript/php&#039;&gt;&lt;br&gt;
&lt;input type=&#039;button&#039; value=&quot;Update Twitter&quot; onclick=&#039;update_twitter();&#039;&gt;
</code></pre></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F06%2Fupdate-twitter-using-command-line-javascript-or-php.html&amp;linkname=Update%20Twitter%20using%20Command%20Line%2C%20Javascript%2C%20Or%20PHP."><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/06/update-twitter-using-command-line-javascript-or-php.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

