为什么 TweetSharp 会抛出异常?
这是最基本的示例,它抛出异常。
// 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);
以下是例外情况:
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
注意:我在 Ubuntu 10.10 64 位上使用 Mono 2.6。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于初学者,您要创建一个新的“requestToken”变量,一个空变量,具有 null 值,然后尝试使用它来获取访问令牌。您需要使用从 GetRequestToken 调用中实际收到的令牌(您称为“请求”的令牌)。
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').
我遇到了同样的问题,我自己无法重现它,但它会在某些客户端的服务器端定期发生。堆栈跟踪和错误描述与您得到的类似:
我查看了 TweetSharp 代码,现在它可能有点过时了(v.2.3)。请告诉我该问题是否在新版本中得到解决。似乎这里发生了错误:
似乎对 twitter 服务器的请求由于某种原因失败了,但是没有检查 response.Content 是否为空。然后 ParseQueryString 抛出异常。
我的解决方案只是忽略此错误并允许用户重试。看来网络错误、代理服务器或不稳定的连接可能会导致此错误。
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:
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:
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.