I have been do this steps as listed here: https://www.c-sharpcorner.com/uploadfile/b7325a/read-data-from-social-networking-feedssharp47tweets-and-save-t/
and here's the code:
public static List<Status> GetTwitterFeeds()
{
string screenname = "csharpcorner";
var auth = new SingleUserAuthorizer
{
CredentialStore = new InMemoryCredentialStore()
{
ConsumerKey = ConfigurationManager.AppSettings["consumerkey"],
ConsumerSecret = ConfigurationManager.AppSettings["consumersecret"],
OAuthToken = ConfigurationManager.AppSettings["accessToken"],
OAuthTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"]
}
};
var twitterCtx = new TwitterContext(auth);
var ownTweets = new List<Status>();
ulong maxId = 0;
bool flag = true;
var statusResponse = new List<Status>();
statusResponse = (from tweet in twitterCtx.Status
where tweet.Type == StatusType.User
&& tweet.ScreenName == screenname
&& tweet.Count == 200
select tweet).ToList();
if (statusResponse.Count > 0)
{
maxId = ulong.Parse(statusResponse.Last().StatusID.ToString()) - 1;
ownTweets.AddRange(statusResponse);
}
do
{
int rateLimitStatus = twitterCtx.RateLimitRemaining;
if (rateLimitStatus != 0)
{
statusResponse = (from tweet in twitterCtx.Status
where tweet.Type == StatusType.User
&& tweet.ScreenName == screenname
&& tweet.MaxID == maxId
&& tweet.Count == 200
select tweet).ToList();
if (statusResponse.Count != 0)
{
maxId = ulong.Parse(statusResponse.Last().StatusID.ToString()) - 1;
ownTweets.AddRange(statusResponse);
}
else
{
flag = false;
}
}
else
{
flag = false;
}
} while (flag);
return ownTweets;
}
}
The tweets does read however the it would only save the date and time and not the content, any advice? My main aim is to search every couple of minutes if a group has tweeted.
How would I change the search function for this?
Or if there is another easier library as I don't think what I want to do is should be this hard
The article you're referencing is for the older synchronous queries. LINQ to Twitter is now
async. Here's how to do a User Timeline query:Notice that the containing method is
asyncand theStatusType.Userquery has anawait. There are more examples in the LINQ to Twitter downloadable source code.