title: Authentication and header rejection with Twitpic and OAuth
body: <p>I am trying my best to upload images to Twitpic by using PHP and OAuth (PECL extension) and I keep getting the following error:</p>
  
  <blockquote>
    <p>Could not authenticate you (header rejected by twitter)</p>
  </blockquote>
  
  <p>This is my code so far:</p>
  
  <pre><code>$arguments[] = "oauth_consumer_key=" . $this-&gt;consumer_key;
  $arguments[] = "oauth_nonce="        . md5(time());
  $arguments[] = "oauth_signature_method=HMAC-SHA1";
  $arguments[] = "oauth_timestamp="    . time();
  $arguments[] = "oauth_token="        . $this-&gt;oauth_token;
  $arguments[] = "oauth_version=1.0";
  
  $sbs       = oauth_get_sbs("POST", "http://api.twitpic.com/2/upload.xml", $arguments);
  $signature = urlencode(base64_encode(hash_hmac("sha1", $sbs, $this-&gt;consumer_secret . "&amp;", true)));
  
  $arguments[] = "oauth_signature="    . $signature;
  
  sort($arguments);
  
  $headers[] = "X-Auth-Service-Provider: http://api.twitter.com/1/account/verify_credentials.json";
  $headers[] = "X-Verify-Credentials-Authorization: OAuth\n" . implode(",\n", $arguments);
  
  $postfields["key"]     = $this-&gt;api_key;
  $postfields["media"]   = "@$image";
  $postfields["message"] = $message;
  
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, "http://api.twitpic.com/2/upload.xml");
  curl_setopt($curl, CURLOPT_POST, true);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($curl, CURLOPT_VERBOSE, true);
  curl_setopt($curl, CURLOPT_HEADER, true);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  echo curl_exec($curl);
  </code></pre>
  
  <p>Can someone tell me what am I doing wrong?</p>