string oauth_nonce = Utility.RandomString(32); string oauth_timestamp = Utility.Timestamp.ToString(); string oauth_signature = null; string encodedTweet = HttpUtility.UrlEncode(tweet); string signingKey = HttpUtility.UrlEncode(ConsumerSecret) + "&" + HttpUtility.UrlEncode(AccessTokenSecret); string requestLine = "POST https://api.twitter.com/1.1/statuses/update.json HTTP/1.1"; string requestBody = "status=" + encodedTweet; string paramsString = "oauth_consumer_key=" + HttpUtility.UrlEncode(ConsumerKey) + "&oauth_nonce=" + HttpUtility.UrlEncode(oauth_nonce) + "&oauth_signature_method=" + HttpUtility.UrlEncode("HMAC-SHA1") + "&oauth_timestamp=" + oauth_timestamp + "&oauth_token=" + HttpUtility.UrlEncode(AccessToken) + "&oauth_version=" + HttpUtility.UrlEncode("1.0") + "&" + requestBody; string signatureBase = "POST&" + HttpUtility.UrlEncode("https://api.twitter.com/1.1/statuses/update.json") + "&" + HttpUtility.UrlEncode(paramsString); byte[] signatureBytes = Sha.ComputeHMACSHA1(Encoding.UTF8.GetBytes(signingKey), Encoding.UTF8.GetBytes(signatureBase)); oauth_signature = HttpUtility.ConvertToBase64String(signatureBytes); byte[] requestBodyBytes = Encoding.UTF8.GetBytes(requestBody); string otherHeaders = "Host: api.twitter.com" + CRLF + "Connection: Close" + CRLF + "Accept: */*" + CRLF + "User-Agent: Tuitduino v0.1" + CRLF + "Content-Type: application/x-www-form-urlencoded" + CRLF + "Content-Length: " + requestBodyBytes.Length; string authorization = "Authorization: OAuth oauth_consumer_key=\"" + HttpUtility.UrlEncode(ConsumerKey) + "\", " + "oauth_nonce=\"" + HttpUtility.UrlEncode(oauth_nonce) + "\", " + "oauth_signature=\"" + HttpUtility.UrlEncode(oauth_signature) + "\", " + "oauth_signature_method=\"HMAC-SHA1\", " + "oauth_timestamp=\"" + oauth_timestamp + "\", " + "oauth_token=\"" + HttpUtility.UrlEncode(AccessToken) + "\", " + "oauth_version=\"1.0\""; string fullRequest = requestLine + CRLF + otherHeaders + CRLF + authorization + CRLF + CRLF + requestBody; byte[] requestBytes = Encoding.UTF8.GetBytes(fullRequest); using (var socket = Network.Connect()) { socket.Send(requestBytes, requestBytes.Length, 0); }
Hi guys, I'm new to netduino and I'm trying to send a POSTrequest to update an status to Twitter API, at this moment I generate the request and send it using raw sockets but it always return 403 Authentication Required, but when I grab the same request and send it vía Fiddler everything goes OK. Can any of you tell me what is wrong? I'm thinking that it might has something to do with indicating the end of the body message. Here is my code: