从搜索实体获取结果以进行Twitter搜索 [英] Getting Results from Search entity for twitter search

查看:174
本文介绍了从搜索实体获取结果以进行Twitter搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用linq-to-twitter,我想传递一个标签以从中搜索并收集数据(文本,用户名,用户图片.我可以返回搜索实体,但我想走得更远才能找到文字,并且在文档中说Search实体有一个result字段,它是SearchEntities的列表,但对我而言却没有出现.在以下两种情况下,我都看到了下面的红线:

Im using linq-to-twitter and I want to pass in a tag to search from and collect the data (the text, username, user picture. I can return a search entity, but I want to go further to find the text, and in the docs it says the Search entity has a result field which is a list of SearchEntities, but it is not appearing for me. I got the red lines under it for both of the below cases:

情况1:

        using (var twitterCtx = new TwitterContext())
                    {
                      var searchResults =
                         (from search in twitterCtx.Search
                         where search.Type == SearchType.Search &&
                             search.Query == tag &&
                             search.IncludeEntities == true
                         select search)
                        .SingleOrDefault();

                        searchResults.Results.ForEach(entry =>
                        {
                            ....

和情况2 :(我只是为了一个简单的示例将其嵌入)

and Case 2: (I just embedded it for a quick example)

var latestTweets= (from tweet in twitterCtx.Search
               where tweet.Count == 200 &&
                     tweet.Hashtag.Contains(tag)
               select tweet).Take(20);


              foreach (var tweet in latestTweets)
              {
                  foreach(var tweet2 in tweet.Result)

.结果只是没有显示出来... API文档

.Result just isn't showing up... API doc

推荐答案

这里发生了一些事情.首先,LINQ to Twitter现在实现了Twitter API v1.1,这意味着所有查询(包括Search)都必须经过身份验证.我在保护安全性方面,这里有关于如何在LINQ to Twitter上使用OAuth的文档.您的应用程序.可下载的源代码和示例页面包含示例也是.

There are a few things happening here. First, is that LINQ to Twitter now implements Twitter API v1.1, which means that all queries, including Search, must be authenticated. I have documentation here on how to use OAuth with LINQ to Twitter at Securing Your Applications. The downloadable source code and Sample page has examples too.

偶尔发生的下一件事是Twitter可能不会为您的查询返回数据.他们的搜索引擎针对某些类型的查询进行了优化,并且不保证搜索引擎的质量响应.您可以通过访问他们的搜索页进行检查,并输入与您要在LINQ上使用的查询相同的数据到Twitter.它们也具有高级搜索的链接.

The next thing that happens occasionally is that Twitter might not be returning data for your query. Their search engine is optimized for certain types of queries and they don't guarantee a search engine quality response. You can check this by visiting their Search page and enter the same data as the query you're trying to use with LINQ to Twitter. They have a link for Advanced Search too.

如果您认为LINQ to Twitter可能有问题,请使用Fiddler捕获HTTP流量,并向我显示请求和响应.注意:请务必清除凭据,以免它们在公共场合出现.

If you think something might be wrong with LINQ to Twitter, capture the HTTP traffic with Fiddler and show me the request and response. Note: be sure to sanitize credentials so they don't appear in public.

另一件事是,使用Contains运算符的第二个查询将不起作用. LINQ to Twitter仅在过滤器中使用相等运算符,这些运算符成为发送到Twitter的参数.如果要进行更复杂的查询,请首先从Twitter获取数据,然后执行LINQ to Objects查询.其理由是,Twitter API无法识别特殊的运算符,而引入这种虚假性不会让您知道网络上真正发生的事情,这会影响应用程序的性能.

Another thing is that the second query, using the Contains operator, won't work. LINQ to Twitter only uses equality operators in filters, which become the parameters sent to Twitter. If you want more sophisticated queries, first get the data back from Twitter and then do a LINQ to Objects query. The rationale is that the Twitter API doesn't recognize special operators and introducing this artificiality wouldn't let you know what's truly happening on the wire, which affects the performance of your app.

@JoeMayo

这篇关于从搜索实体获取结果以进行Twitter搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆