Getting Results from Search entity for twitter search

点点圈 提交于 2019-12-11 03:22:13

问题


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:

Case 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 =>
                        {
                            ....

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)

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


回答1:


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.

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.

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.

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



来源:https://stackoverflow.com/questions/13419058/getting-results-from-search-entity-for-twitter-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!