private string GetRandomTweetForUser(string screenName, int maxTweets) { string result = string.Empty; var twitterHelper = UserStateRepository.GetTwitterHelper(); var random = new Random(); string timeLineUrlFormat = ConfigurationManager.AppSettings["twitterTimeLineUrlFormat"]; var timeLineRequestSettings = new TimeLineRequestSettings { Count = maxTweets, ExcludeReplies = true, IncludeRts = true, RequestUrlFormat = timeLineUrlFormat, ScreenName = screenName, TrimUser = true }; var timeLineJson = twitterHelper.GetTimelineJson(timeLineRequestSettings); var timeLineItems = JsonConvert.DeserializeObject<List<TimeLine>>(timeLineJson); if (timeLineItems == null || timeLineItems.Count == 0) { result = string.Empty; } else if (timeLineItems.Count == 1) { result = timeLineItems[0].Text; } else { int randomIndexForTimeLineItem = random.Next(0, timeLineItems.Count); var randomTimeLineItem = timeLineItems[randomIndexForTimeLineItem]; result = randomTimeLineItem.Text; } return result; }
public string GetTimelineJson(TimeLineRequestSettings requestSettings) { var timeLineJson = string.Empty; var authResponse = Authenticate(); var url = requestSettings.BuildRequestUrl(); timeLineJson = JsonUtil.RequestJson(url, authResponse.TokenType, authResponse.AccessToken); return timeLineJson; }