rate_limit_status called from .NET WebClient class

4 views
Skip to first unread message

J.D.

unread,
Mar 22, 2009, 11:04:16 PM3/22/09
to Twitter Development Talk
I must be doing something wrong. If I call rate_limit_status with
CURL, I can see 2 different counts, depending on if I pass my
credentials or not. If I do the same thing from a .NET application, I
always get the non-authenticated (IP address limit) results.

I know setting the WebClient credentials this way works, as I call
other twitter API's after authenticating, plus I can call
verify_credentials this way and it works.

Can anyone see what I'm missing or screwing up?

public void TestLimitInfo()
{
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential( "myuser", "mypass" );

string data = wc.DownloadString( "http://twitter.com/account/
rate_limit_status.json" );
MessageBox.Show( data );

} // GetLimitInfo

TIA,
J.D.

Andrew Badera

unread,
Mar 23, 2009, 5:30:28 AM3/23/09
to twitter-deve...@googlegroups.com
Do an http trace, see if different headers are getting sent.

Thanks-
- Andy Badera
- and...@badera.us
- (518) 641-1280
- Tech Valley Code Camp 2009.1: http://www.techvalleycodecamp.com/
- Google me: http://www.google.com/search?q=andrew+badera

James Deville

unread,
Mar 23, 2009, 12:56:27 AM3/23/09
to twitter-deve...@googlegroups.com
If WebClient works the way HttpWebRequest does, it sends 2 requests. The first is an unauthenticated request to get the auth header, the second is the authenticated response (authenticated to the highest mutually agreeable auth scheme). The problem for Twitter is that the first response will count against unauthenticated requests, and the second counts against the authenticated requests.

I made it work for Witty by manually attaching the BasicAuth header to the webrequest before we sent it. I don't know if WebClient allows that. You may want to consider going with HttpWebRequest and HttpWebResponse.

JD

J.D.

unread,
Mar 23, 2009, 4:38:21 PM3/23/09
to Twitter Development Talk
Cool, thanks James.

J.D.

unread,
Mar 23, 2009, 10:26:10 PM3/23/09
to Twitter Development Talk
WebClient does support adding the header. Adding this worked:

wc.Headers.Add( "Authorization", "Basic " + EncodeBase64
( "username:password" ) );



Reply all
Reply to author
Forward
0 new messages