0

开始使用 Twitter API 并选择使用 Twitterizer 库与 API 交互。目前正在使用一个测试项目来完成一些简单的任务,我遇到了一个问题,我似乎无法在论坛或堆栈上找到任何信息。

设置

  1. 使用 Twitterizer 版本 2.4 (NuGet)
  2. 使用 NewtonSoft JSON 版本 4.0.2(由于序列化问题不得不从 4.0.8 降级)
  3. .Net 4.0/MVC 项目

这是引发异常的代码片段:

var token = dbContext.TwitterProfiles.Where(x => x.TwitterId == MySuperSecretId).First();
var oAuthToken = new OAuthTokens
    {
        AccessToken = token.Token,
        AccessTokenSecret = token.Secret,
        ConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"],
        ConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"]
    };

TwitterResponse<TwitterStatusCollection> mentionsResponse = TwitterTimeline.RetweetsOfMe(oAuthToken);

最后一行吐出 Null Ref Exception

堆栈跟踪:

   at Twitterizer.Commands.RetweetsOfMeCommand.Init()
   at Twitterizer.Core.CommandPerformer.PerformAction[T](ICommand`1 command)
   at Twitterizer.TwitterTimeline.RetweetsOfMe(OAuthTokens tokens, RetweetsOfMeOptions options)
   at Twitterizer.TwitterTimeline.RetweetsOfMe(OAuthTokens tokens)
   at TwitterTest.Controllers.HomeController.GetRetweets() in C:\Users\Tommy\Documents\Visual Studio 2010\Projects\TwitterTest\TwitterTest\Controllers\HomeController.cs:line 85
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

我已经看到了关于库中空引用异常的上一个问题,但该问题出现在以前的版本(2.3.1)上。有人遇到过这个/知道一个参数或我应该发送到这个函数/等的东西吗?我应该说我已经成功使用 Timeline.Mentions 和 User.GetFollowers 函数没有问题,所以这告诉我我的库配置有点正确......

4

1 回答 1

0

好的 - 我可能有它,但我会先做更多的测试。这个特定的函数有一个重载版本,其中 RetweetsOfMeOptions 作为第二个参数,在我的示例中,我没有使用这个版本。但是,如果我添加这行代码:

var options = new RetweetsOfMeOptions {Count = 25, UseSSL = false};

并更新我的函数调用以使用重载调用:

TwitterResponse<TwitterStatusCollection> mentionsResponse = TwitterTimeline.RetweetsOfMe(oAuthToken, options);

我没有得到错误。一旦我确定是这样 - 我将作为潜在问题发布到 Twitterizer 论坛/错误跟踪器。

于 2012-02-22T01:48:12.457 回答