コード例 #1
0
        public JsonResult GetCityTweets(string cityName)
        {
            TwitterViewModel model = new TwitterViewModel
            {
                ProfileName = string.Empty,
                FollowerCount = 0,
                FollowingCount = 0,
                TweetList = new List<TweetViewModel>()
            };

            var searchParameter = new TweetSearchParameters("")
            {
                Lang = Language.English,
                //hard coding the geo location for newyork
                GeoCode = Geo.GenerateGeoCode(Geo.GenerateCoordinates(-74.006, 40.742), 1000, DistanceMeasure.Miles)
            };
            var tweets = Search.SearchTweets(searchParameter);

            foreach (var item in tweets.OrderByDescending(res => res.CreatedAt))
            {
                model.TweetList.Add(new TweetViewModel
                {
                    TweetText = item.Text,
                    CreatedAt = String.Format("{0:d/M/yyyy HH:mm:ss}", item.CreatedAt),
                    CreatedBy = item.CreatedBy.Id.ToString(),
                    HashTag = item.Hashtags.Any() ? item.Hashtags[0].Text : ""
                });
            }

            return Json(model, JsonRequestBehavior.AllowGet);
        }
コード例 #2
0
        public JsonResult GetUserDetails(string id, string key, string geo)
        {
            string message = "";
            TwitterViewModel model = new TwitterViewModel { TweetList = new List<TweetViewModel>() };

            if (!string.IsNullOrEmpty(id))
            {
                var user = Tweetinvi.User.GetUserFromScreenName(id);

                model.ProfileName = user.Name;
                model.FollowerCount = user.FollowersCount;
                model.FollowingCount = user.FriendsCount;

            }

            string query = string.IsNullOrEmpty(key) ? "" : key + " ";
            query += string.IsNullOrEmpty(id) ? "" : "from:" + id;

            var searchParameter = new TweetSearchParameters("")
            {
                Lang = Language.English,

                SearchQuery = query.TrimEnd()
            };

            if(!string.IsNullOrEmpty(geo))
            {
                string[] result = geo.Split(',');
                if (!string.IsNullOrEmpty(result[0].Trim()))
                {
                    searchParameter.GeoCode = new GeoCode(double.Parse(result[1].TrimEnd()), double.Parse(result[0].TrimEnd()), double.Parse(result[2].TrimEnd()), DistanceMeasure.Miles);
                }
            }

            var tweets = Search.SearchTweets(searchParameter);

            foreach (var item in tweets.OrderByDescending(res => res.CreatedAt))
            {
                model.TweetList.Add(new TweetViewModel
                {
                    TweetText = item.Text,
                    CreatedAt = String.Format("{0:d/M/yyyy HH:mm:ss}", item.CreatedAt),
                    CreatedBy = item.CreatedBy.Name,
                    HashTag = item.Hashtags.Any() ? item.Hashtags[0].Text : ""
                });
            }

            return Json(model, JsonRequestBehavior.AllowGet);
        }