title: first step oauth 1.0 with tumblr
body: <p>ok, so i am trying to write a simple script that can authenticate with tumblr using oauth. for reasons beyond the scope of this question, i can't use any libraries, so i have to do this on my own. It seems i fail from the very first step of this. This is my code so far:</p>
  
  <pre><code>$requestTokenUrl    = "http://www.tumblr.com/oauth/request_token";
  $authorizeUrl       = "http://www.tumblr.com/oauth/authorize";
  $accessTokenUrl     = "http://www.tumblr.com/oauth/access_token";
  
  $oauthCallbackUrl       = MY_URL;
  $consumerKey            = MY_KEY;
  $oauthTimestamp         = time();
  $nonce                  = md5(mt_rand());
  $oauthSignatureMethod   = "HMAC-SHA1";
  $oauthVersion           = "1.0";
  
  $sigBase = "POST&amp;" . rawurlencode($requestTokenUrl) . "&amp;"
   . rawurlencode(
      "oauth_callback=" . rawurlencode($oauthCallbackUrl)
      . "oauth_consumer_key=" . rawurlencode($consumerKey)
      . "&amp;oauth_nonce=" . rawurlencode($nonce)
      . "&amp;oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
      . "&amp;oauth_timestamp=" . $oauthTimestamp
      . "&amp;oauth_version=" . $oauthVersion
   );
  
  $sigKey = $consumerSecret . "&amp;";
  
  $oauthSig = base64_encode(hash_hmac("sha1", $sigBase, $sigKey, true));
  
  $ch = curl_init();
  
  curl_setopt($ch, CURLOPT_URL, $requestTokenUrl);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt($ch, CURLOPT_VERBOSE, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
   'Authorization: OAuth oauth_consumer_key="' . $consumerKey . '",
      oauth_timestamp="' . $oauthTimestamp . '",
      oauth_nonce="' . $nonce . '",
      oauth_callback="' . $oauthCallbackUrl . '",
      oauth_signature_method="' . $oauthSignatureMethod . '",
      oauth_version="' . $oauthVersion . '",
      oauth_signature="' . $oauthSig . '"'
  ));
  
  curl_setopt($ch, CURLOPT_POST, 1);
  
  $output = curl_exec($ch);
  </code></pre>
  
  <p>The problem is, that i wrote the above code, following a tutorial about oauth and twitter. I tried to combine some of the not so good tumblr api documentation. And now i get an oauth 400 bad request response which i cant debug somehow. Actually the oauth response is this:</p>
  
  <pre><code>HTTP/1.0 400 Bad request
  Cache-Control: no-cache
  Connection: close
  Content-Type: text/html
  
  &lt;html&gt;&lt;body&gt;&lt;h1&gt;400 Bad request&lt;/h1&gt;
  Your browser sent an invalid request.
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>and the curl_getinfo shows this:</p>
  
  <pre><code>'url' =&gt; string 'http://www.tumblr.com/oauth/request_token' (length=41)
  'content_type' =&gt; string 'text/html' (length=9)
  'http_code' =&gt; int 400
  'header_size' =&gt; int 97
  'request_size' =&gt; int 545
  'filetime' =&gt; int -1
  'ssl_verify_result' =&gt; int 0
  'redirect_count' =&gt; int 0
  'total_time' =&gt; float 0.377313
  'namelookup_time' =&gt; float 0.028666
  'connect_time' =&gt; float 0.198192
  'pretransfer_time' =&gt; float 0.198388
  'size_upload' =&gt; float 0
  'size_download' =&gt; float 90
  'speed_download' =&gt; float 238
  'speed_upload' =&gt; float 0
  'download_content_length' =&gt; float -1
  'upload_content_length' =&gt; float -1
  'starttransfer_time' =&gt; float 0.37721
  'redirect_time' =&gt; float 0
  'redirect_url' =&gt; string '' (length=0)
  'primary_ip' =&gt; string '66.6.43.30' (length=10)
  'certinfo' =&gt; 
   array (size=0)
     empty
  'primary_port' =&gt; int 80
  'local_ip' =&gt; string '192.168.1.70' (length=12)
  'local_port' =&gt; int 52189
  </code></pre>
  
  <p>Is there a way to know what is going wrong? Any help would be appreciated. Thank you.</p>