Twitter API 1.1 Webrequest Problem.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Basically my code works fine with a single Request query like
https://api.twitter.com/1.1/friends/ids.json?screen_name=SimplyBenGenius
but after i add the other variables
https://api.twitter.com/1.1/friends/ids.json?cursor=-1&screen_name=twitterapi&count=5000
i get a 401 error oauth application keys

oauth implementation details
Dim oauth_version = "1.0"
Dim oauth_signature_method = "HMAC-SHA1"

unique request details
Dim oauth_nonce = Convert.ToBase64String(New ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()))
Dim timeSpan = DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0, _
0, DateTimeKind.Utc)
Dim oauth_timestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString()

message api details

Dim resource_url = "https://api.twitter.com/1.1/friends/ids.json"
Dim screen_name = "UPDATEME"
Dim Cursor = "-1"
Dim TwitterCount = "5000"


create oauth signature
Dim baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" + "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&screen_name={6}"

Dim baseString = String.Format(baseFormat, oauth_consumer_key, oauth_nonce, oauth_signature_method, oauth_timestamp, oauth_token, _
oauth_version, Uri.EscapeDataString(screen_name))

baseString = String.Concat("GET&", Uri.EscapeDataString(resource_url), "&", Uri.EscapeDataString(baseString))

Console.WriteLine(baseString.ToString)


Dim compositeKey = String.Concat(Uri.EscapeDataString(oauth_consumer_secret), "&", Uri.EscapeDataString(oauth_token_secret))

Dim oauth_signature As String
Using hasher As New HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey))
oauth_signature = Convert.ToBase64String(hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)))
End Using

create the request header
Dim headerFormat = "OAuth oauth_nonce=""{0}"", oauth_signature_method=""{1}"", " + "oauth_timestamp=""{2}"", oauth_consumer_key=""{3}"", " + "oauth_token=""{4}"", oauth_signature=""{5}"", " + "oauth_version=""{6}"""

Dim authHeader = String.Format(headerFormat, Uri.EscapeDataString(oauth_nonce), Uri.EscapeDataString(oauth_signature_method), Uri.EscapeDataString(oauth_timestamp), Uri.EscapeDataString(oauth_consumer_key), Uri.EscapeDataString(oauth_token), _
Uri.EscapeDataString(oauth_signature), Uri.EscapeDataString(oauth_version))

RichTextBox1.Text += authHeader & Environment.NewLine

make the request

ServicePointManager.Expect100Continue = False


Dim PreCursor = "&cursor=" + Uri.EscapeDataString(Cursor)
Dim postBody = "screen_name=" + Uri.EscapeDataString(screen_name)
Dim twitcount = "&count=" + Uri.EscapeDataString(TwitterCount)


cursor=-1&screen_name=twitterapi&count=5000


resource_url += "?" + postBody + PreCursor + twitcount


Dim request As HttpWebRequest = DirectCast(WebRequest.Create(resource_url), HttpWebRequest)

RichTextBox1.Text += resource_url & Environment.NewLine




request.Headers.Add("Authorization", authHeader)
request.Method = "GET"
request.ContentType = "application/x-www-form-urlencoded"


Dim response As WebResponse = request.GetResponse()


Dim responseData As String = New StreamReader(response.GetResponseStream()).ReadToEnd()Any help would be much grateful, its properly something simple but i just cant see it..

View the full article
 
Back
Top