I'm starting out a new c# project where I want to extract some tweets, nothing specific at the moment, just to get started...
I created a developer user at the Twitter API and created a new app and got all the consumerkey and accesstoken...
According to this link - https://github.com/JoeMayo/LinqToTwitter/wiki/Single-User-Authorization Everything should work fairly smooth but I just don't get any results...
My project is a .net console application and this is my code which is almost copy-paste from the reference I mentioned above:
var auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = ...,
ConsumerSecret = ...,
AccessToken = ...,
AccessTokenSecret = ...
}
};
var twitterCtx = new TwitterContext(auth);
var searchResponse =
(from search in twitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == "\"LINQ to Twitter\""
select search)
.SingleOrDefault();
if (searchResponse != null && searchResponse.Statuses != null)
searchResponse.Statuses.ForEach(tweet =>
Console.WriteLine(
"User: {0}, Tweet: {1}",
tweet.User.ScreenNameResponse,
tweet.Text));
I don't even know how to identify if the authentication process was successful, Any assistance please? Thanks!
You missed the
awaiton the search query:LINQ to Twitter is
async, which means that all methods in the call chain must beasyncand you mustawaitcalls. What is probably happening is that the method returns before thesearchResponseis populated and you don't see results. Adding theawaitmakes the code wait for the response.