title: Twitter POST problems using api 1.1
body: <p>We've just changed to Twitter api 1.1, and now Tweeting doesn't work &amp; returns an error "The remote server returned an error: (400) Bad Request."  Researching on SO about this suggests that it's something to do with authentication, but we are sending the accessToken &amp; secret which we've just got from the login page. It all worked fine with api 1.0. The code is -</p>
  
  <pre><code>    public void Tweet(Action&lt;string&gt; response, string message)
      {
          StringBuilder sb = new StringBuilder();
          sb.Append("POST&amp;");
          sb.Append(Uri.EscapeDataString(_postUrl));
          sb.Append("&amp;");
  
          string oauthNonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
          string timeStamp = MakeTimestamp();
  
          var dict = new SortedDictionary&lt;string, string&gt;
          {
              { "oauth_consumer_key", _oAuthConfig.ConsumerKey },
              { "oauth_nonce", oauthNonce },
              { "oauth_signature_method", "HMAC-SHA1" },
              { "oauth_timestamp", timeStamp },
              { "oauth_token", _accessToken },
              { "oauth_version", "1.0" },
          };
  
          foreach (var keyValuePair in dict)
          {
              sb.Append(Uri.EscapeDataString(string.Format("{0}={1}&amp;", keyValuePair.Key, keyValuePair.Value)));
          }
  
          string encodedMessage = EscapeAdditionalChars(Uri.EscapeDataString(message));
          sb.Append(Uri.EscapeDataString("status=" + encodedMessage));
  
          string signatureBaseString = sb.ToString();
  
  
          // create the signature
  
          string signatureKey = Uri.EscapeDataString(_oAuthConfig.ConsumerSecret) + "&amp;" + Uri.EscapeDataString(_accessTokenSecret);
  
          var hmacsha1 = new HMACSHA1(new ASCIIEncoding().GetBytes(signatureKey));
  
          string signatureString = Convert.ToBase64String(hmacsha1.ComputeHash(new ASCIIEncoding().GetBytes(signatureBaseString)));
  
  
          // create the headers
  
          string authorizationHeaderParams = String.Empty;
  
          authorizationHeaderParams += "OAuth ";
          authorizationHeaderParams += "oauth_consumer_key=\"" + _oAuthConfig.ConsumerKey + "\", ";
          authorizationHeaderParams += "oauth_nonce=\"" + oauthNonce + "\", ";
          authorizationHeaderParams += "oauth_signature=\"" + Uri.EscapeDataString(signatureString) + "\", ";
          authorizationHeaderParams += "oauth_signature_method=\"" + "HMAC-SHA1" + "\", ";
          authorizationHeaderParams += "oauth_timestamp=\"" + timeStamp + "\", ";
          authorizationHeaderParams += "oauth_token=\"" + _accessToken + "\", ";
          authorizationHeaderParams += "oauth_version=\"" + "1.0" + "\"";
  
          string messageToPost = EscapeAdditionalChars(SpacesToPlusSigns(message));
  
  
          // initialise the WebClient
  
          WebClient client = new WebClient();
  
          client.Headers [HttpRequestHeader.Authorization] = authorizationHeaderParams;
  
          client.UploadDataCompleted += (s, eArgs) =&gt;
          {
              if (eArgs.Error == null)
                  response(DefaultSuccessMessage());
              else
                  response(eArgs.Error.Message);
          };
  
          try
          {
              Uri uri = new Uri(_postUrl);
              try
              {
                  client.UploadDataAsync(uri, "POST", Encoding.UTF8.GetBytes("status=" + messageToPost));
              }
              catch (WebException e)
              {
                  Log.Info("TwitterService-&gt;Tweet web error: " + e.Message);
                  response(DefaultErrorMessage());
              }
              catch (Exception e)
              {
                  // Can happen if we had already favorited this status
                  Log.Info("TwitterService-&gt;Tweet error: " + e.Message);
                  response(DefaultErrorMessage());
              }
          }
          catch (WebException e)
          {
              Log.Info("TwitterService-&gt;Tweet web error 2: " + e.Message);
              response(DefaultErrorMessage());
          }
          catch (Exception e)
          {
              Log.Info("TwitterService-&gt;Tweet error 2: " + e.Message);
              response(DefaultErrorMessage());
          }
      }
  </code></pre>
  
  <p>Basically, I'd like to be able to Tweet without using any 3rd party libraries such as Twitterizer (even TweetStation seems to be broken with api 1.1) - surely it can't be that difficult!</p>
  
  <p>Any help much appreciated, as it feels a bit like a brick wall at the moment - I'm also fairly new to c#, which doesn't help...</p>
  
  <p>Edited to show code which wasn't clear previously.</p>