I would like to do a search using linq to twitter v.4. the query that I have managed to accomplish so far gets the user tweets.
Is there a way to search the same way as you would in the twitter search box?
e.g. when I type music in the search box in the browser it shows all the relevant tweets.
I found this code online but am getting the error message 'StatusType'does not contain a definition for search.
var statusTweets = from tweet in twitterContext.Search
where tweet.Type == StatusType.Search &&
tweet.Query =="twitter"&&
tweet.Count == 2 &&
tweet.IncludeEntities == true
select tweet;
LINQ to Twitter is async, so the code you posted is incomplete. Here's how that would work:
var statusTweets =
await
(from tweet in twitterContext.Search
where tweet.Type == SearchType.Search &&
tweet.Query =="SearchQuery" &&
tweet.Count == 2 &&
tweet.IncludeEntities == true
select tweet)
.ToListAsync();
Notice the differences are await
and ToListAsync()
. If you are having trouble with async code, do a search for 'C# async' and you will find a lot of material. Stephen Cleary's Blog is also a good async resource.
There's documentation on the LINQ to Twitter wiki on Searching Twitter.
The Samples folder also has demos on how to use LINQ to Twitter. The Console Samples are more comprehensive and other samples are single demos of a few commands and queries so you can get a feeling for how LINQ to Twitter works with those technologies.
The part of your question about "Like the Twitter Search Box" is very general and unrelated to LINQ to Twitter and you might want to ask separate, more targeted questions about that. Please review the Stack Overflow Help section on Asking a Question to help you fine tune your question for the best results.