AjaxControlToolkit.TwitterAPI.GetSearch C# (CSharp) Method

GetSearch() public method

public GetSearch ( string search, int count ) : List
search string
count int
return List
        public List<TwitterStatus> GetSearch(string search, int count)
        {
            var result = Query("https://api.twitter.com/1.1/search/tweets.json",
                new[] {
                    new KeyValuePair<String, String>("q", search),
                    new KeyValuePair<String, String>("count", count.ToString())
                });
            var serializer = new JavaScriptSerializer();
            var searchResult = serializer.Deserialize<Status>(result);
            if(searchResult == null || searchResult.Statuses == null)
                return null;

            return searchResult.Statuses.Select(s => new TwitterStatus {
                CreatedAt = ParseDateTime(s.created_at),
                Text = s.text,
                User = new TwitterUser {
                    Id = s.user.id,
                    Description = s.user.description,
                    Location = s.user.location,
                    Name = s.user.name,
                    ProfileImageUrl = s.user.profile_image_url,
                    ScreenName = s.user.screen_name
                }
            }).ToList();
        }

Usage Example

Example #1
0
        /// <summary>
        /// Get the search results from the Twitter API. Cache the results.
        /// </summary>
        /// <returns></returns>
        private IList <TwitterStatus> GetSearch()
        {
            var cacheKey = String.Format("__TwitterSearch_{0}_{1}", this.Search, this.Count);

            var results = (IList <TwitterStatus>) this.Context.Cache[cacheKey];

            if (results == null)
            {
                var api = new TwitterAPI();
                try {
                    results = api.GetSearch(this.Search, this.Count);
                } catch {
                    return(null);
                }
                this.Context.Cache.Insert(
                    cacheKey,
                    results,
                    null,
                    DateTime.UtcNow.AddSeconds(this.CacheDuration),
                    System.Web.Caching.Cache.NoSlidingExpiration
                    );
            }

            return(results);
        }
All Usage Examples Of AjaxControlToolkit.TwitterAPI::GetSearch