【发布时间】:2015-04-28 19:35:05
【问题描述】:
我在我的 Xamarin.IOS 统一应用程序中使用来自 Nuget 的 LinqToTwitter v3.1.1 和仅应用程序身份验证,以使用这个不错的库的搜索选项显示来自 TwitterAccount 的推文列表。但是,在执行简单搜索时,我在 TwitterQueryProvider 上收到未处理的 NullReference 异常。
我写的代码如下:
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);
}
}
下面的部分堆栈跟踪:
{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 }
执行 Search 并将其放入 var searchResponse 时会发生错误。我已验证身份验证已成功并且已设置承载令牌。除了乔·梅奥本人在LINQ to Twitter Project site on Codeplex 上提供的简单示例之外,没有做过任何花哨的事情。
我也尝试了一些不使用 LinqToTwitter 的方法,该方法可以(使用相同的凭据)接收推文列表,但由于序列化原因,我选择使用 LinqToTwitter。
感觉好像我在这里遗漏了一些明显的东西,比如设置一些令牌或在某处授权,但找不到它。包含在 codeplex 源文件中的演示控制台项目似乎工作得很好。这里有什么想法吗?
【问题讨论】:
-
有什么,有人吗?仍然有效!
标签: c# xamarin.ios xamarin linq-to-twitter