<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<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>Twitpic OAuth &#8211; I&#8217;m Stuck &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/2010/05/twitpic-oauth-im-stuck/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Thu, 01 May 2025 08:14:45 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>Twitpic OAuth &#8211; I&#8217;m Stuck &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Twitpic OAuth - I'm Stuck]]></title>
		<link>https://shkspr.mobi/blog/2010/05/twitpic-oauth-im-stuck/</link>
					<comments>https://shkspr.mobi/blog/2010/05/twitpic-oauth-im-stuck/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Sun, 23 May 2010 20:15:18 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[twitpic]]></category>
		<category><![CDATA[twitter]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=2073</guid>

					<description><![CDATA[Twitpic has implemented an OAuth API. No more having to hand out passwords to all and sundy.  Only I&#039;m too much of a dunderhead to get it working.  Perhaps it&#039;s a combination of heatstroke or this rotten head-cold, but I just can&#039;t see what I&#039;m doing wrong.  Any help much appreciated.  The easy bit.  It&#039;s easy to post the data to Twitpic  $media_data = array(     &#039;media&#039; =&#62;…]]></description>
										<content:encoded><![CDATA[<p>Twitpic has implemented an <a href="https://web.archive.org/web/20100522065016/http://dev.twitpic.com/docs/2/upload/">OAuth API</a>. No more having to hand out passwords to all and sundy.  Only I'm too much of a dunderhead to get it working.  Perhaps it's a combination of heatstroke or this rotten head-cold, but I just can't see what I'm doing wrong.  Any help much appreciated.</p>

<h2 id="the-easy-bit"><a href="https://shkspr.mobi/blog/2010/05/twitpic-oauth-im-stuck/#the-easy-bit">The easy bit.</a></h2>

<p>It's easy to post the data to Twitpic</p>

<pre><code class="language-php">$media_data = array(
    'media' =&gt; '@'.$_FILES['media']['tmp_name'],
    'message' =&gt; html_entity_decode($_POST['message']),
    'key'=&gt;'123465789132465'
);
curl_setopt($ch,CURLOPT_POSTFIELDS,$media_data);
</code></pre>

<h2 id="oauth-credentials"><a href="https://shkspr.mobi/blog/2010/05/twitpic-oauth-im-stuck/#oauth-credentials">OAuth Credentials</a></h2>

<p>Using <a href="http://twitter.com/abraham">Abrahams</a> <a href="http://github.com/abraham/twitteroauth">OAuth library for PHP</a>, it's easy to get the required OAuth data.</p>

<pre><code class="language-php">require_once('OAuth.php');
// instantiating OAuth customer
$consumer = new OAuthConsumer(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
// instantiating signer
$sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
// user's token
list($oauth_token, $oauth_token_secret) = explode('|', $GLOBALS['user']['password']);
$token = new OAuthConsumer($oauth_token, $oauth_token_secret);

// signing URL
$fakeurl = 'https://twitter.com/account/verify_credentials.xml';
$request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $fakeurl, array());
$request-&gt;sign_request($sha1_method, $consumer, $token);
$OAuthurl = $request-&gt;to_url();
</code></pre>

<h2 id="the-tricky-bit"><a href="https://shkspr.mobi/blog/2010/05/twitpic-oauth-im-stuck/#the-tricky-bit">The Tricky Bit</a></h2>

<p>I'm following the header example in the <a href="https://web.archive.org/web/20100522065016/http://dev.twitpic.com/docs/2/upload/">API documentation</a>. Passing these variable to Twitpic is where I seem to go wrong.</p>

<pre><code class="language-php">$header = array(
      'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json',
      'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/"'
   );
</code></pre>

<p>I then modify the second header so it reads</p>

<pre><code class="language-php">"X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/",
oauth_consumer_key="aaaaaaa",
oauth_nonce="bbbbbbbbbbb",
oauth_signature="ccccccccccccc%3D",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="123456798",
oauth_token="15948715-dddddddddd",
oauth_version="1.0""
</code></pre>

<h2 id="the-error"><a href="https://shkspr.mobi/blog/2010/05/twitpic-oauth-im-stuck/#the-error">The Error</a></h2>

<p>401 "Could not authenticate you (header rejected by twitter)."</p>

<p>GAH!</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=2073&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2010/05/twitpic-oauth-im-stuck/feed/</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
			</item>
	</channel>
</rss>
