/// <summary> /// gets the tweets /// </summary> /// <param name="userName"></param> /// <param name="count"></param> /// <returns></returns> public TwitterSearchResult GetTweets(string userName, int count) { TwitterSearchResult retVal = new TwitterSearchResult(); try { // Get the access var aToken = OuthAuthenticationHelper.GetAccessToken(); if (aToken.HasAuthToken) { string url = string.Format(TwitterConstants.TWEETS_GET_UNFORMATTED_URL, count, userName); // using the access toke get the tweets var result = HttpUtils.MakeHttpGetRequest(url, aToken.OAuthToken.GetAuthenticationHeaderValue(), "application/json"); // only id repsosne is ok proceed if (result.ReplyStatusCode == HttpStatusCode.OK) { retVal.Tweets = new JavaScriptSerializer().Deserialize <Tweet[]>(result.ResponseBody); } else { retVal.ErrorMessage = result.ResponseBody; } } } catch (Exception exc) { retVal.ErrorMessage = exc.Message; } return(retVal); }
private void Button_Click(object sender, RoutedEventArgs e) { //string verifier = codiceVerifica.Text; // <-- This is input into your application by your user //OAuthAccessToken access = service.GetAccessToken(requestToken, verifier); // Step 4 - User authenticates using the Access Token // service.AuthenticateWith(access.Token, access.TokenSecret); /* * IAsyncResult result = service.BeginListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions()); * IEnumerable<TwitterStatus> tweets = service.EndListTweetsOnHomeTimeline(result); * * foreach (var tweet in tweets) * { * provatxtbox.Text+=tweet.User.ScreenName +": "+ tweet.Text+"\n"; * } */ SearchOptions options = new SearchOptions(); options.Q = "#moncler"; options.Lang = "fr"; options.Count = 100; IAsyncResult result = service.BeginSearch(options); TwitterSearchResult tweets = service.EndSearch(result); // if(tweets.Statuses.Count<TwitterStatus>() > 0) foreach (var tweet in tweets.Statuses) { // if(tweet.Language=="it") provatxtbox.Text += tweet.Language + "\n"; } }
public void Initialize() { _mockTwitter = new Mock <ITwitterService>(); _mockTwitter.Setup(p => p.SearchAsync(It.IsAny <SearchOptions>())).Returns( Task.Factory.StartNew(() => { var result = new TwitterSearchResult(); result.Statuses = new List <TwitterStatus> { new TwitterStatus() }; return(result); })); _mockRepository = new Mock <ISearchWordRepository>(); _searchWord = new SearchWord { LastTweetId = 100, Word = Guid.NewGuid().ToString() }; _searchWord.Product = new Product(); _mockRepository.Setup(p => p.ReadAll()).Returns(() => { SearchWord[] products = { _searchWord }; return(products.AsQueryable()); }); _mockResultRepository = new Mock <ISearchResultRepository>(); DependencyContainer.Instance.RegisterInstance(_mockRepository.Object); DependencyContainer.Instance.RegisterInstance(_mockResultRepository.Object); DependencyContainer.Instance.RegisterInstance(_mockTwitter.Object); }
public async Task <List <Status> > SearchTwittsByKeyWord(string keyword, int count = 15, string accessToken = null) { if (accessToken == null) { accessToken = await GetAccessToken(); } //To search with the twiter api we need to pas someting like this: // https://api.twitter.com/1.1/search/tweets.json?q=%40twitterapi //base URL for searches: https://api.twitter.com/1.1/search/tweets.json //search query: "q=%40twitterapi" - can be taken from https://twitter.com/search //https://api.twitter.com/1.1/search/tweets.json?q=бойко%20борисов&src=typd var request = new HttpRequestMessage(HttpMethod.Get, string.Format("https://api.twitter.com/1.1/search/tweets.json?q={0}&src=typd&count=15", keyword)); request.Headers.Add("Authorization", "Bearer " + accessToken); var httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.SendAsync(request); var jsonString = await response.Content.ReadAsStringAsync(); System.IO.File.WriteAllText(@"D:\TwitterResult.txt", jsonString); TwitterSearchResult twitterSearchResults = JsonConvert.DeserializeObject <TwitterSearchResult>(jsonString); List <Status> results = new List <Status>(); foreach (var result in twitterSearchResults.statuses) { results.Add(result); } return(results); }
private void SearchCallback(TwitterSearchResult result, TwitterResponse response, TwitterStatus status) { if (result == null || response.StatusCode != HttpStatusCode.OK || result.Statuses == null) { RaiseCallback(new List <TwitterStatus>(), response); // report the error TryFinish(); return; } okResponse = response; searchCache.BulkAdd(result.Statuses.Except(searchCache)); if (result.Statuses.Count() >= 90) { // There are still more statuses to retrieve Interlocked.Increment(ref pendingCalls); service.Search(new SearchOptions { Q = "to:" + status.AuthorName, SinceId = status.Id, MaxId = result.Statuses.Min(x => x.Id), Count = 100 }, (rs, rp) => SearchCallback(rs, rp, status)); } else { // Finished! AddCachedResult(status.AuthorName, status.Id); } RetrieveRepliesFromCache(status); TryFinish(); }
public MainPage() { InitializeComponent(); TRes = new TwitterSearchResult(); this.DataContext = TRes; }
private void messageResult(TwitterSearchResult result, TwitterResponse response) { TwitterStatus[] statusesArray = result.Statuses.ToArray(); for (int i = 0; i < statusesArray.Length; i++) { string name = statusesArray[i].Author.ScreenName; string imageurl = statusesArray[i].Author.ProfileImageUrl; string text = statusesArray[i].Text; System.Console.WriteLine(name); System.Console.WriteLine(text); System.Console.WriteLine(result.ToString()); } }
protected void ReceiveSearch(TwitterSearchResult result, TwitterResponse response) { requestsInProgress--; IsLoading = false; if (result == null || result.Statuses == null) { if (Error != null) { Error(response); } return; } GenericReceive(result.Statuses.Cast <ITweetable>(), response); }
public TwitterSearchResult CreateTwitterSearchResult(dynamic obj) { TwitterSearchResult result = new TwitterSearchResult(); //try //{ // result.id = obj.id; // result.text = obj.text; //} //catch (Exception ex) //{ // Console.WriteLine(ex.ToString()); //} return(result); }
protected override IData OnGetData() { TwitterSearchResult tweets = Service.Search(new SearchOptions() { Geocode = GeoCode, Lang = Lang, Locale = Locale, Q = Query, Resulttype = ResultType, IncludeEntities = IncludeEntities, Count = Count, //SinceId = SinceId, }); return(DataEnumerable(tweets.Statuses)); }
//[HttpPost] public ActionResult SearchTweetsForUser(SearchEntity user) { if (!string.IsNullOrEmpty(user.UserName)) { TwitterSearchResult tweetSearchResult = GetTweets(user.UserName, user.NumberOfTweets); if (string.IsNullOrEmpty(tweetSearchResult.ErrorMessage)) { ViewData[TwitterSearchResult.PARAM_NAME] = tweetSearchResult.Tweets; } else { ModelState.AddModelError("", tweetSearchResult.ErrorMessage); } } return(View("Output")); }
private void GetOldTweets() { //TwitterService("consumer key", "consumer secret"); //AuthenticateWith("Access Token", "AccessTokenSecret"); var service = new TwitterService("UNrDr7NEn3yl9hro0xt0ocMxy", "1gDaYaKVJqPkPHXCkiRoLtp5COfeKIfD6vcswUz27vQUzQx3yC"); service.AuthenticateWith("265655738-PWXyCPdrv0t1qFNHM1W3hRXdPU7H08oizz5kGdDG", "spauwDp6woHF1ClpGq8t6b3hzRTJsZTpDe6mtY0FEWpOq"); bool keepLooping = true; long loopingID = 0; List <TwitterStatus> oldTweets = new List <TwitterStatus>(); TwitterStatus lastTweet = new TwitterStatus(); SearchOptions options = new SearchOptions { Q = "#acme", Count = 5 }; TwitterSearchResult searchResults = service.Search(options); oldTweets = searchResults.Statuses.ToList(); loopingID = oldTweets[0].Id; while (keepLooping) { try { options = new SearchOptions { Q = "#acme", MaxId = loopingID, Count = 100 }; searchResults = service.Search(options); oldTweets.AddRange(service.Search(options).Statuses); lastTweet = oldTweets[oldTweets.Count - 1]; if (loopingID != lastTweet.Id) { loopingID = lastTweet.Id; } else { break; } } catch { keepLooping = false; } } insertDB(oldTweets); }
public void StartGettingQuestions() { SearchOptions searchOptions = new SearchOptions(); searchOptions.Q = Properties.Settings.Default.twitterSearchTag; searchOptions.Count = 30; searchOptions.Resulttype = TwitterSearchResultType.Mixed; searchOptions.IncludeEntities = false; TwitterSearchResult tweets = service.Search(searchOptions); if (tweets != null) { foreach (var tweet in tweets.Statuses) { string[] question = { tweet.Text, tweet.User.ScreenName }; QuestionsList.Add(question); } } }
public IEnumerable <TwitterStatus> getTwit(string input) { var service = new TwitterService("HsE9x7KSWhqyb7CQhxhFWN2oF", "GlUtr9Hy7Rq0UwcKmA8MCbSD1AORoTN83LvA8oYGool1yUFG1S"); //AuthenticateWith("Access Token", "AccessTokenSecret"); service.AuthenticateWith("2489399222-AR5SyQDsDZ7bqc23eT8QNBDauVFDX8PWdnrWZcu", "FMAJel0Q3ivViyvGRLDWljeDKbANrRj0D8XS3shlmVGCt"); TwitterSearchResult result = service.Search(new SearchOptions { Q = input, Count = 500 }); if (result == null) { return(null); } //ScreenName="screeen name not username", Count=Number of Tweets / www.Twitter.com/mcansozeri. IEnumerable <TwitterStatus> tweets = result.Statuses; return(tweets); }
private void messageResult(TwitterSearchResult result, TwitterResponse response) { if (result != null) { json = result.ToString(); TwitterStatus[] statusesArray = result.Statuses.ToArray(); for (int i = 0; i < statusesArray.Length; i++) { item.Add(new TwiterItem() { Message = statusesArray[i].Text, UserName = statusesArray[i].Author.ScreenName, ImageSource = statusesArray[i].Author.ProfileImageUrl }); } Dispatcher.BeginInvoke(() => { listBox1.ItemsSource = item; }); } }
protected override void OnProcessData <T>(Processor p, ProcessingNode <T> node) { var data = GetData(0); var q = data.Value.ToString(); if (!String.IsNullOrEmpty(q)) { TwitterService service = new TwitterService(); service.AuthenticateWith(token, tokenSecret, accessToken, accessTokenSecret); TwitterSearchResult res = service.Search(new SearchOptions { Q = q }); IEnumerable <TwitterStatus> status = res.Statuses; var first = res.Statuses.LastOrDefault(); if (first != null) { SetData(0, new DataContainer(first.Text)); } } }
public async Task <IHttpActionResult> GetTweets(string hash = null) { try { if (string.IsNullOrWhiteSpace(hash)) { return(Ok(new Tweet[] { })); } TwitterService service = new TwitterService(); service.AuthenticateWith(ConsumerKey, ConsumerSecret, AccessToken, AccessTokenSecret); if (!hash.StartsWith("#")) { hash = "#" + hash; } TwitterSearchResult tweets = service.Search(new SearchOptions { Q = hash }); if (tweets == null) { return(Ok(new Tweet[] { })); } return(Ok(tweets.Statuses.Select(x => new Tweet { Text = x.Text, Id = x.Id }).ToArray())); } catch (Exception e) { return(Ok(new Tweet[] { })); } }
public void GetHashTag_Tap() { string apiKey = "Z33WED4YapoVlGIgW4PqdtNi0"; string apiSecret = "HSu7l6t8ZrV5vPCOGnHFafUKo6qK59PaCidPLONZPsgjkQoMap"; string accessToken = "837241580910161922-sB4w2dvts24puBKs2m7MhdJi4380m9K"; string accesstokSec = "KLKq7lN9u5zEp4z180W58kFOcG89hM3trUyCc6UgpqORb"; var service = new TwitterService(apiKey, apiSecret); service.AuthenticateWith(accessToken, accesstokSec); TwitterSearchResult tweets = service.Search(new SearchOptions { Q = "#p1ctureb0t", Lang = "en", Count = 1 }); IEnumerable <TwitterStatus> status = tweets.Statuses; foreach (var item in status) { user = "******" + item.User.ScreenName; value = " " + item.Text; //MessageBox.Show(user+value); } }
private static IEnumerable <TwitterStatus> Search(SearchOptions option) { TwitterSearchResult result = service.Search(option); if (result == null) { return(new List <TwitterStatus>()); } IEnumerable <TwitterStatus> returns = result.Statuses; if (returns == null || !returns.Any()) { return(returns); } int last = (option.Count ?? 0) - returns.Count(); Console.WriteLine("取得したツイート数 : {0, 3}, 先頭のID : {1}, 末尾のID : {2}, ほしいツイートの残り数 : {3}", returns.Count(), returns.First().Id, returns.Last().Id, last); if (last > 0) { try { SearchOptions next = option; next.MaxId = returns.Last().Id - 1; next.Count = last; returns = returns.Concat(Search(next)); } catch (Exception e) { Console.Error.WriteLine("Twitter検索の際に例外が発生しました(メッセージ : {0})", e.Message); } } return(returns); }
public ActionResult atom_result(string Mention, string PDAM, string PJS, string PJU, string Disdik, string Diskominfo, string Algorithm) { /* Variabel Global Untuk Search*/ mention_search = string.Copy(Mention); PDAM_search = string.Copy(PDAM); PJS_search = string.Copy(PJS); PJU_search = string.Copy(PJU); Disdik_search = string.Copy(Disdik); Diskominfo_search = string.Copy(Diskominfo); /*Local Variable*/ string[] tes = new string[5]; tes[0] = PDAM_search.ToLower(); tes[1] = PJS_search.ToLower(); tes[2] = PJU_search.ToLower(); tes[3] = Disdik_search.ToLower(); tes[4] = Diskominfo_search.ToLower(); List <string[]> pemkot = new List <string[]>(); List <string> menti = mention_search.Split(';').ToList <string>(); /*Use wether BM or KMB Algorithm*/ if (Algorithm.Equals("BM")) { use_BM = true; } else { use_BM = false; } //TwitterService var service = new TwitterService("5q4cQb8Q9YyOl35vPRZLx8Jjq", "UmFtUuVDIsrOrLI3g4qs8HqYGWjIQ3O4ghfhAu6Sb5Y9QkN2lx"); //Authenticate service.AuthenticateWith("178535721-rRphja9pNDIDK3p1JOx55Joly19vgzRTFBivuNmB", "XU4EFfVN4tlwbGu75POv4FurI571cznMIw3IBPrqIgWSG"); List <TwitterStatus> tweet = new List <TwitterStatus>(); //Search by key if (menti.Count != 0) { foreach (string ment in menti) { TwitterSearchResult searchRes = service.Search(new SearchOptions { Q = ment.ToLower(), Count = 100, }); var tweets = searchRes.Statuses; if (tweets != null) { foreach (TwitterStatus t in tweets) { tweet.Add(t); } } } } /*Beginning of iti*/ //Seperate semicolom (;) for (int i = 0; i < 5; i++) { pemkot.Add(tes[i].Split(';')); } /**============FILTER===========**/ stat = new List <TwitterStatus> [6]; for (int i = 0; i < 6; i++) { stat[i] = new List <TwitterStatus>(); } KMP kmp = new KMP(); BM bm = new BM(); for (int j = 0; j < 5; j++) { for (int i = 0; i < pemkot[j].Length; i++) { string x = pemkot[j][i]; List <TwitterStatus> tweetx = new List <TwitterStatus>(tweet); foreach (TwitterStatus t in tweetx) { if (use_BM == false) { //KMP Algorithm if (kmp.KMPSearch(t.Text, x)) { stat[j].Add(t); tweet.Remove(t); } } else { //BM ALgorithm if (bm.BMSearch(t.Text, x)) { stat[j].Add(t); tweet.Remove(t); } } } } } stat[5] = new List <TwitterStatus>(tweet); tweet.Clear(); LocationAnalyzer la = new LocationAnalyzer(); List <string>[] location = new List <string> [6]; for (int o = 0; o < 6; o++) { location[o] = new List <string>(); foreach (TwitterStatus tx in stat[0]) { string temp = la.getTempat(tx.Text); if (temp != "") { location[o].Add(temp); } } } ViewBag.PDAM = stat[0]; ViewBag.PJU = stat[1]; ViewBag.Dissos = stat[2]; ViewBag.Disdik = stat[3]; ViewBag.Diskominfo = stat[4]; ViewBag.Other = stat[5]; ViewBag.PDAMloc = location[0]; ViewBag.PJUloc = location[1]; ViewBag.Dissosloc = location[2]; ViewBag.Disdikloc = location[3]; ViewBag.Diskominfloc = location[4]; ViewBag.Otherloc = location[5]; ViewBag.OtherlocCount = location[5].Count; ViewBag.PDAM_Count = stat[0].Count; ViewBag.PJU_Count = stat[1].Count; ViewBag.Dissos_Count = stat[2].Count; ViewBag.Disdik_Count = stat[3].Count; ViewBag.Diskominfo_Count = stat[4].Count; ViewBag.Other_Count = stat[5].Count; /*END of ITI*/ return(View()); }
public TweetsModel GetTweets(int numberOfResults, bool adminOverview) { var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); var tweetsModel = new TweetsModel { ShowAdminOverView = adminOverview }; var member = umbracoHelper.MembershipHelper.GetCurrentMember(); if (member == null || member.IsHq() == false) { tweetsModel.ShowAdminOverView = false; } List <TwitterStatus> filteredTweets = new List <TwitterStatus>(); try { var tweets = UmbracoContext.Current.Application.ApplicationCache.RuntimeCache.GetCacheItem <IEnumerable <TwitterStatus> >("UmbracoSearchedTweets", () => { var service = new TweetSharp.TwitterService( ConfigurationManager.AppSettings["twitterConsumerKey"], ConfigurationManager.AppSettings["twitterConsumerSecret"]); service.AuthenticateWith( ConfigurationManager.AppSettings["twitterUserAccessToken"], ConfigurationManager.AppSettings["twitterUserAccessSecret"]); var options = new SearchOptions { Count = 100, Resulttype = TwitterSearchResultType.Recent, Q = "umbraco" }; TwitterSearchResult results = null; try { results = service.Search(options); } catch (Exception ex) { LogHelper.Error <TwitterService>("Searching Twitter did not work", ex); } return(results?.Statuses); }, TimeSpan.FromMinutes(2)); if (tweets != null) { var settingsNode = umbracoHelper.TypedContentAtRoot().FirstOrDefault(); if (settingsNode != null) { var usernameFilter = settingsNode.GetPropertyValue <string>("twitterFilterAccounts") .ToLowerInvariant().Split(',').Where(x => x != string.Empty).ToArray(); var wordFilter = settingsNode.GetPropertyValue <string>("twitterFilterWords") .ToLowerInvariant().Split(',').Where(x => x != string.Empty); filteredTweets = tweets.Where(x => x.Author.ScreenName.ToLowerInvariant().ContainsAny(usernameFilter) == false && x.Text.ToLowerInvariant().ContainsAny(wordFilter) == false && x.Text.StartsWith("RT ") == false) .Take(numberOfResults) .ToList(); } } tweetsModel.Tweets = filteredTweets; } catch (Exception ex) { LogHelper.Error <TwitterService>("Could not get tweets", ex); } return(tweetsModel); }
public static string TwitterPrevPageLink(string sectionName, TwitterSearchResult result, string seoFriendlyQuestion) { if (!String.IsNullOrEmpty(result.PreviousPage)) return String.Format("<a href=\"/{0}/{1}/{2}\" class=\"prev\">Newer</a> «", sectionName, seoFriendlyQuestion, result.Page - 1); else return string.Empty; }
public static string TwitterCurrentPage(TwitterSearchResult result) { return String.Format("Page {0}", result.Page); }
public static string TwitterNextPageLink(string sectionName, TwitterSearchResult result, string seoFriendlyQuestion) { if (!String.IsNullOrEmpty(result.NextPage)) return String.Format("» <a href=\"/{0}/{1}/{2}\" class=\"next\">Older</a>", sectionName, seoFriendlyQuestion, result.Page + 1); else return string.Empty; }
// get by twitter hashtag public Int32 fetch(string tag, Int32 count, Int32 event_id, Int32 template_id) { Int32 total = 0; var service = new TwitterService(_settings.twitter_api_key(), _settings.twitter_api_secret()); service.AuthenticateWith(_settings.twitter_access_token(), _settings.twitter_access_token_secret()); var options = new SearchOptions(); options.Q = "%23" + tag; options.Count = count; options.IncludeEntities = true; options.Lang = "en"; options.Resulttype = TwitterSearchResultType.Recent; Event ev = _events.single(event_id); TwitterSearchResult tweets = new TwitterSearchResult(); try { tweets = service.Search(options); } catch (OverflowException ex) { Console.WriteLine(ex.InnerException); } try { foreach (var item in tweets.Statuses) { Media m = new Media(); m.added_to_db_date = DateTime.Now; m.createdate = item.CreatedDate; m.description = item.Text; m.full_name = item.User.Name; //m.source_id = item.Id.ToString(); if (item.Location != null) { m.latitude = item.Location.Coordinates.Latitude.ToString(); m.longitude = item.Location.Coordinates.Longitude.ToString(); } if (item.Place != null) { m.location_name = item.Place.FullName; } m.likes = item.RetweetCount; m.link = "https://twitter.com/" + item.User.ScreenName + "/status/" + item.Id.ToString(); m.profilepic = item.User.ProfileImageUrl; m.service = "Twitter"; m.event_id = event_id; m.template_id = template_id; foreach (var hashtag in item.Entities.HashTags) { m.tags += "#" + hashtag.Text + " "; } m.username = item.User.ScreenName; // ################## NOW THE IMAGE STUFF foreach (TwitterMedia photo in item.Entities.Media) { m.source_id = photo.IdAsString; m.source = photo.MediaUrl + ":large"; m.width = photo.Sizes.Large.Width; m.height = photo.Sizes.Large.Height; if (photo.MediaType.ToString() != "Photo") { m.is_video = true; } m.approved = true; m.approved_by = 1; m.approved_date = DateTime.Now; } m.source_id = item.IdStr; _media.add(m); total++; } } catch (NullReferenceException ex) { Console.WriteLine(ex.Message + ": " + ex.InnerException); } return(total); }
private void AddTwitterPosts(string hashTag, TwitterConfiguration twitterConfig, ISocialFeedsRepository socialFeedRepo) { // bool isPreviousPost = true; int DescriptionLength = 500; var service = new TwitterService(twitterConfig.ConsumerKey, twitterConfig.ConsumerSecret); service.AuthenticateWith(twitterConfig.Token, twitterConfig.TokenSecret); TwitterSearchResult prevResults = null; TwitterSearchResult currentResults = null; SearchOptions options = new SearchOptions() { Q = hashTag, Count = 100 }; long sinceId = socialFeedRepo.GetMaxTwitterPostId(hashTag); if (sinceId > 0) { options.SinceId = sinceId; options.Resulttype = TwitterSearchResultType.Recent; } currentResults = service.Search(options); sinceId = socialFeedRepo.GetMinTwitterPostId(hashTag); if (sinceId > 0) { options.SinceId = null; options.MaxId = sinceId; prevResults = service.Search(options); } List <Post> posts = new List <Post>(); var parallerOptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount * 2 }; if (currentResults != null && currentResults.Statuses != null) { Parallel.ForEach(currentResults.Statuses, parallerOptions, item => { if (TwitterPostType(item) == PostType.Text && !string.IsNullOrEmpty(item.Id.ToString())) { Post post = new Post(); post.PostSource = SocialNetwork.Twitter; post.SocialNetworkPostId = Convert.ToString(item.Id); post.SocialNetworkUserId = item.User.Id; post.SocialNetworkUsername = item.User.ScreenName; post.PostType = TwitterPostType(item); post.PostUrl = TwitterPostUrl(item); post.ThumbnailUrl = TwitterThumbnailUrl(item); post.SocialNetworkUserPictureUrl = item.User.ProfileImageUrlHttps; post.Description = GetTrimmedString(item.Text, DescriptionLength); post.PostDateCreated = item.CreatedDate; post.IsVIPContent = false; post.hashTag = hashTag; post.Status = PostStatus.Pending; //if (post.PostDateCreated >= Settings.PostDateLimit) //{ posts.Add(post); //} } }); } if (prevResults != null && prevResults.Statuses != null) { Parallel.ForEach(prevResults.Statuses, parallerOptions, item => { if (TwitterPostType(item) == PostType.Text && !string.IsNullOrEmpty(item.Id.ToString())) { Post post = new Post(); post.PostSource = SocialNetwork.Twitter; post.SocialNetworkPostId = Convert.ToString(item.Id); post.SocialNetworkUserId = item.User.Id; post.SocialNetworkUsername = item.User.ScreenName; post.PostType = TwitterPostType(item); post.PostUrl = TwitterPostUrl(item); post.ThumbnailUrl = TwitterThumbnailUrl(item); post.SocialNetworkUserPictureUrl = item.User.ProfileImageUrlHttps; post.Description = GetTrimmedString(item.Text, DescriptionLength); post.PostDateCreated = item.CreatedDate; post.IsVIPContent = false; post.hashTag = hashTag; post.Status = PostStatus.Pending; //if (post.PostDateCreated >= Settings.PostDateLimit) //{ posts.Add(post); //} //else //{ isPreviousPost = false; } } }); } if (posts.Count > 0) { socialFeedRepo.SaveFeeds(posts); //if (!isPreviousPost) //{ // socialFeedRepo.UpdateFeed(hashTag); //} } posts.Clear(); }
private long? CreatePostsFromSearchJson(TwitterSearchResult items, PublicSearchTabModel tab, bool read, bool more) { long? minimumId = null; foreach (var status in items.Statuses) { if (minimumId == null || minimumId.Value > status.Id) minimumId = status.Id; if (!more && status.Id > tab.SinceId) tab.SinceId = status.Id; //二重取得回避 lock (LockObj) { if (tab.Contains(status.Id)) continue; } var post = CreatePostsFromStatusData(status); post.IsRead = read; if ((post.IsMe && !read) && this._readOwnPost) post.IsRead = true; tab.AddPostQueue(post); } return minimumId; }