2012-02-22 50 views
0

開始玩弄Twitter API並選擇使用Twitterizer庫與API進行接口。目前使用測試項目來完成一些簡單的任務,我遇到了一個問題,我似乎無法在論壇或堆棧中找到任何信息。Twitterizer對象參考未設置

的設置

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

最後一行pukes了一個空參考異常

堆棧跟蹤:

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)。任何人都遇到過/知道一個參數或我應該發送到這個函數/ etc?我應該說,我成功地使用了Timeline.Mentions和User.GetFollowers函數沒有問題,所以這告訴我我的庫配置有點正確...

回答

0

好吧 - 我可能有它,但要去做先測試一下。這個特殊的函數有一個重載的版本,其中RetweetsOfMeOptions作爲第二個參數,在我的例子中,我沒有使用這個版本。不過,如果我加入這行代碼:

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

而且更新我的函數調用來使用重載的呼叫:

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

我沒有得到這個錯誤。一旦我確信這是它 - 我會發布到Twitterizer論壇/ bug跟蹤器作爲一個潛在的問題。