public async Task<IActionResult> Tweets(string screenName) { var model = new List<TweetViewModel>(); List<Status> statuses = await twitterService.GetUserTweetsAsync(screenName); foreach (var status in statuses) { var tweet = new TweetViewModel { TweetId = status.StatusID, TweetedOn = status.CreatedAt, InReplyToScreenName = status.InReplyToScreenName, Text = status.Text, Url = "https://twitter.com/" + status.ScreenName + "/status/" + status.StatusID }; model.Add(tweet); } return View("Index", model); }
/// <summary> /// Performs a search based on the search query and returns those tweets. /// </summary> /// <param name="searchString"></param> /// <returns></returns> public async Task<List<TweetViewModel>> GetSearchResultsAsync(string searchString) { var tweets = new List<TweetViewModel>(); List<Status> searchResponse = await twitterContext.Search .Where(t => t.Type == SearchType.Search) .Where(t => t.Query == searchString) .SelectMany(t => t.Statuses) .ToListAsync(); foreach (var status in searchResponse) { var tweet = new TweetViewModel { TweetId = status.StatusID, TweetedOn = status.CreatedAt, InReplyToScreenName = status.InReplyToScreenName, Text = status.Text, ScreenName = status.User.ScreenNameResponse, Url = "https://twitter.com/" + status.User.ScreenNameResponse + "/status/" + status.StatusID }; tweets.Add(tweet); } return tweets; }
/// <summary> /// Gets all tweets performed by the configured user. /// </summary> /// <returns></returns> public async Task<List<TweetViewModel>> GetBotTweetsAsync() { var tweets = new List<TweetViewModel>(); List<Status> statuses = await twitterContext.Status .Where(t => t.Type == StatusType.User) .Where(t => t.ScreenName == configuration["Twitter:ScreenName"]) .ToListAsync(); foreach (var status in statuses) { var tweet = new TweetViewModel { TweetId = status.StatusID, TweetedOn = status.CreatedAt, InReplyToScreenName = status.InReplyToScreenName, Text = status.Text, Url = "https://twitter.com/" + status.ScreenName + "/status/" + status.StatusID }; tweets.Add(tweet); } return tweets; }