Twitter API 1.1 Getting Followers using cursors

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
this is driving me actually crazy, twitter recently moved over to API 1.1 thus making us change some of our applications to the new version but i can get the base code working fine without the cursors flag but as soon as i add the cursors in it just throws an exception.
this is my base code that works all fine and tandy

Dim oauth_token = " "
Dim oauth_token_secret = " "
Dim oauth_consumer_key = " "
Dim oauth_consumer_secret = " "

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 status = "Updating status via REST API if this works"
Dim resource_url = "https://api.twitter.com/1.1/followers/ids.json"

Dim screen_name = "SimplyBenGenius"
Dim count = "5000"
Dim cursor = "-1"
create oauth signature
Dim baseFormat = "count={7}&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), Uri.EscapeDataString(count), Uri.EscapeDataString(cursor))

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

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))


make the request

ServicePointManager.Expect100Continue = False

Dim postBody = "screen_name=" + Uri.EscapeDataString(screen_name)

Dim postbody2 = "count=" + Uri.EscapeDataString(count)
resource_url += "?" + postBody + "&" + postbody2
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(resource_url), HttpWebRequest)
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()


RichTextBox1.Text = responseData


it works perfectly well, returning the first 5000 ids without a problem but when it is included it just simply returns nothing but my Signature base string is identical to the one that twitter generates as a test.. but when i include the cursor it fails Dim baseFormat = "count={7}&cursor={8}&oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" + "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&screen_name={6}"

any help would be great its driving me insane, if its something simple i apologizes im new to VB

View the full article
 
Back
Top