我在我的Xamarin.IOS統一應用程序中使用Nuget的LinqToTwitter v3.1.1和僅使用應用程序的身份驗證,以使用此良好庫的搜索選項顯示來自TwitterAccount的推文列表。但是,執行簡單搜索時,我在TwitterQueryProvider上收到未處理的NullReference異常。NullReferenceException使用LinqToTwitter搜索功能
我寫的代碼如下:下面的堆棧跟蹤的
var credentialStore = new InMemoryCredentialStore
{
ConsumerKey = "MyTwitterKey",
ConsumerSecret = "MyTwitterSecret"
};
var authorizer = new ApplicationOnlyAuthorizer { CredentialStore = credentialStore };
await authorizer.AuthorizeAsync();
var twitterCtx = new TwitterContext(authorizer);
var searchResponse = await (from search in twitterCtx.Search
where search.Type == SearchType.Search
&& search.Query == "Microsoft"
select search)
.SingleOrDefaultAsync();
if (searchResponse != null && searchResponse.Statuses != null)
{
foreach (var tweet in searchResponse.Statuses)
{
Debug.WriteLine("User: {0}, Tweet: {1}", tweet.User.ScreenNameResponse, tweet.Text);
}
}
部分:在執行搜索並投入使用var searchResponse
{System.NullReferenceException: Object reference not set to an instance of an object
at LinqToTwitter.TwitterQueryProvider+<ExecuteAsync>d__6`1[System.Collections.Generic.IEnumerable`1[LinqToTwitter.Search]].MoveNext() [0x00000] in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000b] in [somepath]/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Object].GetResult() [0x00034] in [somepath]/System.Runtime.CompilerServices/ConfiguredTaskAwaitable_T.cs:62
at LinqToTwitter.TwitterExtensions+<ToListAsync>d__11`1[LinqToTwitter.Search].MoveNext() [0x00000] in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000b] in [somepath]/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
at System.Runtime.CompilerServices.TaskAwaiter`1[System.Collections.Generic.List`1[LinqToTwitter.Search]].GetResult() [0x00034] in [somepath]/System.Runtime.CompilerServices/TaskAwaiter_T.cs:59
at [somepath].TwitterService+<GetTweets>d__2.MoveNext() [0x0014f] in [somepath]\TwitterService.cs:27 }
的錯誤發生。我已驗證身份驗證已成功並設置了bearertoken。除了Joe Mayo自己在LINQ to Twitter Project site on Codeplex上提供的簡單例子外,沒有其他花哨的東西被完成。
我也試過一些不使用LinqToTwitter的工作(使用相同的憑據)直到接收推文列表,但由於序列化的原因,我選擇了LinqToTwitter。
感覺就像我錯過了一些明顯的東西,例如設置某個標記或授權某處,但無法找到它。包含來自codeplex源文件的演示控制檯項目似乎工作得很好。這裏的任何想法?
任何人,任何人?仍然有效! – Hutjepower