I’m creating an application to send out tweets from a vb.NET web application. I’ve got code writing an oAuth header and processing the requests, but I just receive either a 401:Unauthorized, or a 400: bad request. I’ve also attempted just copy/pasting one of the auth headers from the API oAuth tool in the control panel for testing to verify it is not that, but I get the same response.
I want to first make sure this is working with the pre-built oAuth header from the control panel, then I can determine if there is any issue with the code I have to write the headers dynamically.
Any ideas on where the problem may be?
Below is the code I have for actually sending the request:
Dim resource_url As String = "http://api.twitter.com/1.1/statuses/update.json"
Dim authHeader = "OAuth oauth_consumer_key=""XXXX"", oauth_nonce=""XXXX"", oauth_signature=""XXXX"", oauth_signature_method=""HMAC-SHA1"", oauth_timestamp=""1374865953"", oauth_token=""XXXX"", oauth_version=""1.0"""
Dim status = "Updating status via REST API if this works"
Dim postBody = "status=" & Uri.EscapeDataString(status)
ServicePointManager.Expect100Continue = False
Dim request As WebRequest = DirectCast(WebRequest.Create(resource_url), HttpWebRequest)
request.Headers.Add("Authorization", authHeader)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
Using stream As IO.Stream = request.GetRequestStream()
Dim content As Byte() = ASCIIEncoding.ASCII.GetBytes(postBody)
stream.Write(content, 0, content.Length)
End Using
Dim objresponse As WebResponse = request.GetResponse()