Reputation: 73295
This is the most BASIC example possible and it's throwing an exception.
// Pass your credentials to the service
TwitterService service = new TwitterService(API_KEY,API_SECRET);
service.UserAgent = "StackBot";
// Step 1 - Retrieve an OAuth Request Token
OAuthRequestToken request = service.GetRequestToken();
// Step 2 - Redirect to the OAuth Authorization URL
Uri uri = service.GetAuthorizationUri(request);
Console.WriteLine(uri.ToString());
// Step 3 - Exchange the Request Token for an Access Token
string verifier = "123456"; // <-- This is input into your application by your user
OAuthRequestToken requestToken = new OAuthRequestToken();
OAuthAccessToken access = service.GetAccessToken(requestToken, verifier);
Here is the exception:
Unhandled Exception: System.ArgumentNullException: Argument cannot be null. Parameter name: query at System.Compat.Web.HttpUtility.ParseQueryString (System.String query, System.Text.Encoding encoding) [0x00000] in :0 at System.Compat.Web.HttpUtility.ParseQueryString (System.String query) [0x00000] in :0 at TweetSharp.TwitterService.GetRequestToken (System.String callback) [0x00000] in :0 at TweetSharp.TwitterService.GetRequestToken () [0x00000] in :0 at Namespace.Class.Main (System.String[] args) [0x00049] in Main.cs:179
Note: I'm using Mono 2.6 on Ubuntu 10.10 64-bit.
Upvotes: 3
Views: 1550
Reputation: 11898
I had the same issue, can't reproduce it myself but it happens periodically on server side with some clients. The stack trace and error description is similar of what you got:
InnerException: Value cannot be null. Parameter name: query at System.Compat.Web.HttpUtility.ParseQueryString(String query, Encoding encoding) at System.Compat.Web.HttpUtility.ParseQueryString(String query) at TweetSharp.TwitterService.GetRequestToken(String callback)
I looked into TweetSharp code, it may be a bit obsolete nowadays (v. 2.3). Please let me know if the issue fixed in newer versions. It seems that error happens here:
var response = _oauth.Request(request);
SetResponse(response);
var query = HttpUtility.ParseQueryString(response.Content);
It seems that request to twitter server failed for whatever reason, but there's no check if response.Content is empty. Then ParseQueryString throw exception.
My solution was just to ignore this error and allow user to try again. It seems that network error, proxy server or unstable connection may cause this error.
Upvotes: 0
Reputation: 3386
For starters you're creating a new 'requestToken' variable, an empty one, with null values, and then trying to use that to get an access token. You need to use the one you actually received from the call to GetRequestToken (the one you call 'request').
Upvotes: 1