/// <summary> /// this Method Will /// </summary> /// <param name="User">Twitter User Name And Password</param> /// <returns>Return Xml Text With User Details</returns> public XmlDocument Rate_Limit_Status(TwitterUser User) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string response = twtWebReq.PerformWebRequest(User, Globals.RateLimitStatusUrl, "GET", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
public List<string> getFriendsofFriends(string FriendId, TwitterUser twitterUser, string goodProxy) { List<string> followersOfFriend = new List<string>(); XmlDocument xmlDoc = new XmlDocument(); TwitterWebRequest twitterWebRequest = new TwitterWebRequest(); Dictionary<string, string> dic = getUserInfo(twitterUser, FriendId, goodProxy); int noofFollowers = Int32.Parse(dic["NoOfFriends"].ToString()); string FriendIds = ""; int pageno = 1; if (noofFollowers > 5000) { pageno = noofFollowers / 5000; int temp = noofFollowers % 5000; if (temp > 10) pageno++; FriendIds = twitterWebRequest.PerformWebRequest(twitterUser, Globals.getFriendsUrl + FriendId + ".xml?page=" + pageno, "GET", true, goodProxy); } else { FriendIds = twitterWebRequest.PerformWebRequest(twitterUser, Globals.getFriendsUrl + FriendId + ".xml?page=1", "GET", true, goodProxy); } xmlDoc.Load(new StringReader(FriendIds)); XmlNodeList xmlNodeList = xmlDoc.GetElementsByTagName("id"); foreach (XmlNode xmlNode in xmlNodeList) { followersOfFriend.Add(xmlNode.InnerText.ToString()); } return followersOfFriend; }
/// <summary> /// /// </summary> /// <param name="twitterUser"></param> /// <param name="uri"></param> /// <param name="HTTPMethod"></param> /// <param name="IsAuthenticationRequire"></param> /// <param name="goodProxy"></param> /// <returns></returns> public string PerformWebRequest(TwitterUser twitterUser,string uri, string HTTPMethod,bool IsAuthenticationRequire,string goodProxy) { HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(uri ); Request.Method = HTTPMethod; StreamReader readStream; Request.MaximumAutomaticRedirections = 4; Request.MaximumResponseHeadersLength = 4; Request.ContentLength = 0; //Globals.RequestCount++; if(IsAuthenticationRequire) Request.Credentials = new NetworkCredential(twitterUser.TwitterUserName , twitterUser.TwitterPassword); HttpWebResponse Response; string strResponse=""; try { Response = (HttpWebResponse)Request.GetResponse(); Stream receiveStream = Response.GetResponseStream(); readStream = new StreamReader(receiveStream); strResponse = readStream.ReadToEnd(); Response.Close(); readStream.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message ); strResponse = ex.Message; //Logger.LogText("Exception from Twitter:" + ex.Message,""); } return strResponse; }
public override void PostScheduleMessage(dynamic data) { try { oAuthTwitter OAuthTwt = new oAuthTwitter(); TwitterAccountRepository fbaccrepo = new TwitterAccountRepository(); TwitterAccount twtaccount = fbaccrepo.getUserInformation(data.UserId, data.ProfileId); OAuthTwt.CallBackUrl = System.Configuration.ConfigurationSettings.AppSettings["callbackurl"]; OAuthTwt.ConsumerKey = System.Configuration.ConfigurationSettings.AppSettings["consumerKey"]; OAuthTwt.ConsumerKeySecret = System.Configuration.ConfigurationSettings.AppSettings["consumerSecret"]; OAuthTwt.AccessToken = twtaccount.OAuthToken; OAuthTwt.AccessTokenSecret = twtaccount.OAuthSecret; OAuthTwt.TwitterScreenName = twtaccount.TwitterScreenName; OAuthTwt.TwitterUserId = twtaccount.TwitterUserId; #region For Testing // For Testing //OAuthTwt.ConsumerKey = "udiFfPxtCcwXWl05wTgx6w"; //OAuthTwt.ConsumerKeySecret = "jutnq6N32Rb7cgbDSgfsrUVgRQKMbUB34yuvAfCqTI"; //OAuthTwt.AccessToken = "1904022338-Ao9chvPouIU8ejE1HMG4yJsP3hOgEoXJoNRYUF7"; //OAuthTwt.AccessTokenSecret = "Wj93a8csVFfaFS1MnHjbmbPD3V6DJbhEIf4lgSAefORZ5"; //OAuthTwt.TwitterScreenName = ""; //OAuthTwt.TwitterUserId = ""; #endregion TwitterUser twtuser = new TwitterUser(); if (string.IsNullOrEmpty(data.ShareMessage)) { data.ShareMessage = "There is no data in Share Message !"; } JArray post = twtuser.Post_Status_Update(OAuthTwt, data.ShareMessage); Console.WriteLine("Message post on twitter for Id :" + twtaccount.TwitterUserId + " and Message: " + data.ShareMessage); ScheduledMessageRepository schrepo = new ScheduledMessageRepository(); schrepo.updateMessage(data.Id); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Log log = new Log(); log.CreatedDate = DateTime.Now; log.Exception = ex.Message; log.Id = Guid.NewGuid(); log.ModuleName = "TwitterScheduler"; log.ProfileId = data.ProfileId; log.Status = false; LogRepository logRepo = new LogRepository(); logRepo.AddLog(log); } }
public override void PostScheduleMessage(dynamic data) { try { oAuthTwitter OAuthTwt = new oAuthTwitter(); TwitterAccountRepository fbaccrepo = new TwitterAccountRepository(); TwitterAccount twtaccount = fbaccrepo.getUserInformation(data.UserId, data.ProfileId); OAuthTwt.CallBackUrl = System.Configuration.ConfigurationSettings.AppSettings["callbackurl"]; OAuthTwt.ConsumerKey = System.Configuration.ConfigurationSettings.AppSettings["consumerKey"]; OAuthTwt.ConsumerKeySecret= System.Configuration.ConfigurationSettings.AppSettings["consumerSecret"]; OAuthTwt.AccessToken = twtaccount.OAuthToken; OAuthTwt.AccessTokenSecret= twtaccount.OAuthSecret; OAuthTwt.TwitterScreenName = twtaccount.TwitterScreenName; TwitterUser twtuser = new TwitterUser(); JArray post = twtuser.Post_Status_Update(OAuthTwt, data.ShareMessage); Console.WriteLine("Message post on twitter for Id :" + twtaccount.TwitterUserId + " and Message: " + data.ShareMessage); ScheduledMessageRepository schrepo = new ScheduledMessageRepository(); schrepo.updateMessage(data.Id); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
/// <summary> /// This Method Will Check That User is Authenticated Or Not /// </summary> /// <param name="User">Twitter User Name And Password</param> /// <returns>Return Xml Text With User Details</returns> public XmlDocument Verify_Credentials(TwitterUser User) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string response = twtWebReq.PerformWebRequest(User, Globals.VerifyCredentialsUrl, "GET", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// This Method Will Get All Trends Of Twitter /// </summary> /// <param name="User">Twitter User Name And Password</param> /// <returns>Json Text Of Trends</returns> public XmlDocument SearchMethod(TwitterUser User, string SearchKey) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.SearchUrl + SearchKey; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Get", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// Follow Twitter User /// </summary> /// <param name="twitterUser">Twitter UserName And Password</param> /// <param name="UserToFollow">ScreenName Of Whom You Want To Follow</param> /// <returns>Returm Xml</returns> public XmlDocument Friendships_Create(TwitterUser User, string ScreenName) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.FollowerUrl + ScreenName; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Post", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// UnFollow Twitter User /// </summary> /// <param name="twitterUser">Twitter UserName And Password</param> /// <param name="UserToFollow">ScreenName Of Whom You Want To UnFollow</param> /// <returns>Returm Xml</returns> public XmlDocument Friendships_Destroy(TwitterUser User, int UserId) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.UnFollowUrlById + UserId; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Post", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// This Method Will Get All Direct Message Sent By User /// </summary> /// <param name="User">Twitter User Name And Password</param> /// <param name="Count">Number Of DirectMessage Sent By User</param> /// <returns>Xml Text Of DirectMessage Sent By User</returns> public XmlDocument DirectMessage_Sent(TwitterUser User, string Count) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.DirectMessageSentByUserUrl + Count; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Get", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// Get All ReTweets Sent By User /// </summary> /// <param name="User">Twitter User And Password</param> /// <param name="Count">Number Of ReTweets</param> /// <returns>Return XmlText Of ReTweets</returns> public XmlDocument Status_RetweetedByMe(TwitterUser User, string Count) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.RetweetedByMeUrl + Count; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Get", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// This Method Will Retweet /// </summary> /// <param name="User">Twitter User Name And Password</param> /// <param name="UserId">Tweet Id</param> /// <returns></returns> public XmlDocument ReTweetStatus(TwitterUser User, string Id) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.ReTweetStatus + Id + ".xml"; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Post", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// This Method Will Show User Statues By ScreenName /// </summary> /// <param name="User">Twitter User Name And Password</param> /// <param name="UserId">Twitter UserId Of User</param> /// <returns></returns> public XmlDocument ShowStatusByScreenName(TwitterUser User, string ScreenName) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.ShowStatusUrlByScreenName + ScreenName; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Get", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// This Method Will Update Tweets On Twitter /// </summary> /// <param name="User">Twitter UserName And Password</param> /// <param name="StatusText">Status Messages</param> /// <returns>Return Xml Text Of Details</returns> public XmlDocument UpdateStatus(TwitterUser User, string StatusText) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.UpdateStatusUrl + "?status=" + StatusText; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Post", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// This will Send DirectMessage to the User /// </summary> /// <param name="User">Twitter UserName Password</param> /// <param name="DirectMessage">DirectMessage</param> /// <param name="UserId">USerId Whom You Want to Send Direct Message</param> /// <returns></returns> public XmlDocument NewDirectMessage(TwitterUser User, string DirectMessage, string ScreenName) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.NewDirectMessage + "?screen_name=" + ScreenName + "&text=" + DirectMessage; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Post", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// This will Method will delete Direct Message by Direct Message Id /// </summary> /// <param name="User">Twitter UserName and Password</param> /// <param name="DirectMessageId">Direct Message Id</param> /// <returns></returns> public XmlDocument DeleteDirectMessage(TwitterUser User, int DirectMessageId) { TwitterWebRequest twtWebReq = new TwitterWebRequest(); string RequestUrl = Globals.NewDirectMessage + DirectMessageId + ".xml"; string response = twtWebReq.PerformWebRequest(User, RequestUrl, "Post", true, ""); xmlResult.Load(new StringReader(response)); return xmlResult; }
/// <summary> /// This Method Will Update Tweets On Twitter /// </summary> /// <param name="User">Twitter UserName And Password</param> /// <param name="StatusText">Status Messages</param> /// <returns>Return True If Stuatus Sent SuccessFully</returns> public bool UpdateStatus(TwitterUser User, string StatusText) { Twitter.Core.StatusMethods.Status status = new Twitter.Core.StatusMethods.Status(); xmlResult = status.UpdateStatus(User, StatusText); XmlNodeList xmlNodeList = xmlResult.GetElementsByTagName("id"); if (xmlNodeList.Count > 0) { return true; } return false; }
public bool Authenticated(TwitterUser twitterUser,string goodProxy) { string Response = twitterWebRequest.PerformWebRequest(twitterUser, Globals.VerifyCredentialsUrl, "GET", true,goodProxy ); if (Response.Contains("401")) { //Logger.LogText ("Login failed "+Response ); return false; } //Logger.LogText(twitterUser.TwitterUserName +" logged in",null); return true; }
/// <summary> /// This Method Will Check That User Is Authenticatde Or Not /// </summary> /// <param name="User">Twitter UserName And Password</param> /// <returns>Return True If User Is Authenticated</returns> public bool Verify_Credentials(TwitterUser User) { Twitter.Core.AccountMethods.Account account = new Twitter.Core.AccountMethods.Account(); xmlResult = account.Verify_Credentials(User); XmlNodeList xmlNodeList = xmlResult.GetElementsByTagName("user"); foreach (XmlNode xmlNode in xmlNodeList) { //XmlElement idElement = (XmlElement)xmlNode; //twitterUser.UserID = idElement.GetElementsByTagName("id")[0].InnerText; return true; } return false; }
/// <summary> /// Follow Twitter User /// </summary> /// <param name="twitterUser">Twitter UserName And Password</param> /// <param name="UserToFollow">ScreenName Of Whom You Want To Follow</param> /// <returns>Returm True Follow Is Success</returns> public bool FollowUser(TwitterUser twitterUser, int UserToFollow) { try { Twitter.Core.FriendshipMethods.Friendship friendship = new GlobusTwitterLib.Twitter.Core.FriendshipMethods.Friendship(); xmlResult = friendship.Friendships_Create(twitterUser, UserToFollow); return true; } catch { return false; } }
/// <summary> /// UnFollow Twitter User /// </summary> /// <param name="twitterUser">Twitter UserName And Password</param> /// <param name="UserToFollow">ScreenName Of Whom You Want To UnFollow</param> /// <returns>Returm True UnFollow Is Success</returns> public bool UnFollowUser(TwitterUser twitterUser, string UserToUnFollow) { try { Twitter.Core.FriendshipMethods.Friendship friendship = new GlobusTwitterLib.Twitter.Core.FriendshipMethods.Friendship(); xmlResult = friendship.Friendships_Destroy(twitterUser, UserToUnFollow); return true; } catch { return false; } }
/// <summary> /// This Method Will Check That User Is Authenticatde Or Not /// </summary> /// <param name="User">Twitter UserName And Password</param> /// <returns>Return True If User Is Authenticated</returns> public bool Verify_Credentials(TwitterUser User) { Twitter.Core.AccountMethods.Account account = new Twitter.Core.AccountMethods.Account(); xmlResult = account.Verify_Credentials(User); XmlNodeList xmlNodeList = xmlResult.GetElementsByTagName("user"); foreach (XmlNode xmlNode in xmlNodeList) { //XmlElement idElement = (XmlElement)xmlNode; //twitterUser.UserID = idElement.GetElementsByTagName("id")[0].InnerText; return(true); } return(false); }
public List<string> getFollowers(TwitterUser twitterUser,string goodProxy) { List<string> followers=new List<string> (); XmlDocument xmlDoc = new XmlDocument(); TwitterWebRequest twitterWebRequest=new TwitterWebRequest(); string followerIds = twitterWebRequest.PerformWebRequest(twitterUser, Globals.getFollowersUrl + twitterUser.TwitterUserName, "GET", true, goodProxy); xmlDoc.Load(new StringReader(followerIds)); XmlNodeList xmlNodeList = xmlDoc.GetElementsByTagName("id"); foreach (XmlNode xmlNode in xmlNodeList) { followers.Add(xmlNode.InnerText.ToString()); } return followers; }
/// <summary> /// Get FollowersId Of ScreenName /// </summary> /// <param name="twitterUser">Twitter UserName And Password</param> /// <param name="UserToFollow">ScreenName Of Whom You Want To Get FollowersId</param> /// <returns>Returm True UnFollow Is Success</returns> public List <string> FollowersId(TwitterUser twitterUser, string ScreenName) { List <string> lstFollowersId = new List <string>(); Twitter.Core.SocialGraphMethods.SocialGraph socialGraph = new Twitter.Core.SocialGraphMethods.SocialGraph(); xmlResult = socialGraph.FollowersId(twitterUser, ScreenName); XmlNodeList xmlNodeList = xmlResult.GetElementsByTagName("id"); foreach (XmlNode xmlNode in xmlNodeList) { lstFollowersId.Add(xmlNode.InnerText.ToString()); } return(lstFollowersId); }
public int FollowersCount(oAuthTwitter oAuth, string screenname, SortedDictionary<string, string> strdic) { string RequestUrl = "https://api.twitter.com/1/users/lookup.xml?screen_name=" + screenname; string response = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, RequestUrl, strdic); xmlResult.Load(new StringReader(response)); TwitterUser twtUser = new TwitterUser(); XmlNodeList xmlNodeList = xmlResult.GetElementsByTagName("user"); int count = 0; foreach (XmlNode xn in xmlNodeList) { XmlElement idElement = (XmlElement)xn; count = Convert.ToInt32(idElement.GetElementsByTagName("followers_count")[0].InnerText); } return count; }
/// <summary> /// /// </summary> /// <param name="twitterUser"></param> /// <param name="uri"></param> /// <param name="HTTPMethod"></param> /// <param name="IsAuthenticationRequire"></param> /// <param name="goodProxy"></param> /// <returns></returns> public string PerformWebRequest(TwitterUser twitterUser, string uri, string HTTPMethod, bool IsAuthenticationRequire, string goodProxy) { HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(uri); Request.Method = HTTPMethod; StreamReader readStream; Request.MaximumAutomaticRedirections = 4; Request.MaximumResponseHeadersLength = 4; Request.ContentLength = 0; //Globals.RequestCount++; if (IsAuthenticationRequire) { Request.Credentials = new NetworkCredential(twitterUser.TwitterUserName, twitterUser.TwitterPassword); } HttpWebResponse Response; string strResponse = ""; try { Response = (HttpWebResponse)Request.GetResponse(); Stream receiveStream = Response.GetResponseStream(); readStream = new StreamReader(receiveStream); strResponse = readStream.ReadToEnd(); Response.Close(); readStream.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); strResponse = ex.Message; //Logger.LogText("Exception from Twitter:" + ex.Message,""); } return(strResponse); }
public void getTwitterMessages(string UserId, oAuthTwitter OAuth) { TwitterUser twtuser; #region Add Twitter Messages twtuser = new TwitterUser(); try { TimeLine tl = new TimeLine(); JArray data = null; try { data = tl.Get_Statuses_Mentions_Timeline(OAuth); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error("tl.Get_Statuses_Mentions_Timeline ex.StackTrace >> " + ex.StackTrace); logger.Error("tl.Get_Statuses_Mentions_Timeline ex.Message >> " + ex.Message); } objTwitterMessage = new Domain.Socioboard.Domain.TwitterMessage(); foreach (var item in data) { objTwitterMessage.UserId = Guid.Parse(UserId); objTwitterMessage.Type = "twt_mentions"; objTwitterMessage.Id = Guid.NewGuid(); try { objTwitterMessage.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.MessageDate = Utility.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"')); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.TwitterMsg = item["text"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.FromId = item["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.FromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.FromProfileUrl = item["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.InReplyToStatusUserId = item["in_reply_to_status_id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.SourceUrl = item["source"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.ProfileId = objTwitterAccount.TwitterUserId; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.ScreenName = item["user"]["screen_name"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.EntryDate = DateTime.Now; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } if (!objTwitterMessageRepository.checkTwitterMessageExists(objTwitterMessage.MessageId)) { objTwitterMessageRepository.addTwitterMessage(objTwitterMessage); } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error("tl.Get_Statuses_Mentions_Timeline ex.StackTrace >> " + ex.StackTrace); logger.Error("tl.Get_Statuses_Mentions_Timeline ex.Message >> " + ex.Message); } #endregion }
private void getUserTweets(string UserId, oAuthTwitter OAuth) { #region Add User Tweets try { TwitterUser twtuser =new TwitterUser(); JArray Timeline = twtuser.GetStatuses_User_Timeline(OAuth); TwitterMessageRepository twtmsgrepo = new TwitterMessageRepository(); TwitterMessage twtmsg = new TwitterMessage(); foreach (var item in Timeline) { objTwitterMessage.UserId = Guid.Parse(UserId); objTwitterMessage.Type = "twt_usertweets"; try { objTwitterMessage.TwitterMsg = item["text"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.SourceUrl = item["source"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.ScreenName = objTwitterAccount.TwitterScreenName; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.ProfileId = objTwitterAccount.TwitterUserId; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.MessageDate = Utility.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"')); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.InReplyToStatusUserId = item["in_reply_to_status_id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.Id = Guid.NewGuid(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.FromProfileUrl = item["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.FromName = item["user"]["name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterMessage.FromId = item["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } objTwitterMessage.EntryDate = DateTime.Now; try { objTwitterMessage.FromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } if (!objTwitterMessageRepository.checkTwitterMessageExists(objTwitterMessage.MessageId)) { objTwitterMessageRepository.addTwitterMessage(objTwitterMessage); } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error("twtuser.GetStatuses_User_Timeline ex.StackTrace >> " + ex.StackTrace); logger.Error("twtuser.GetStatuses_User_Timeline ex.Message >> " + ex.Message); } #endregion }
public void getTwitterFeeds(string UserId, oAuthTwitter OAuth) { TwitterUser twtuser; #region Add Twitter User Feed twtuser = new TwitterUser(); try { JArray Home_Timeline = twtuser.GetStatuses_Home_Timeline(OAuth); objTwitterFeed = new Domain.Socioboard.Domain.TwitterFeed(); foreach (var item in Home_Timeline) { objTwitterFeed.UserId = Guid.Parse(UserId); objTwitterFeed.Type = "twt_feeds"; try { objTwitterFeed.Feed = item["text"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.SourceUrl = item["source"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.ScreenName = objTwitterAccount.TwitterScreenName; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.ProfileId = objTwitterAccount.TwitterUserId; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.FeedDate = Utility.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"')); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.InReplyToStatusUserId = item["in_reply_to_status_id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.Id = Guid.NewGuid(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.FromProfileUrl = item["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.FromName = item["user"]["name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.FromId = item["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } objTwitterFeed.EntryDate = DateTime.Now; try { objTwitterFeed.FromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } if (!objTwitterFeedRepository.checkTwitterFeedExists(objTwitterFeed.MessageId)) { try { objTwitterFeedRepository.addTwitterFeed(objTwitterFeed); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } } // Edited by Antima[20/12/2014] SentimentalAnalysis _SentimentalAnalysis = new SentimentalAnalysis(); FeedSentimentalAnalysisRepository _FeedSentimentalAnalysisRepository = new FeedSentimentalAnalysisRepository(); try { if (_FeedSentimentalAnalysisRepository.checkFeedExists(objTwitterFeed.ProfileId.ToString(), Guid.Parse(UserId), objTwitterFeed.Id.ToString())) { if (!string.IsNullOrEmpty(objTwitterFeed.Feed)) { string Network = "twitter"; _SentimentalAnalysis.GetPostSentimentsFromUclassify(Guid.Parse(UserId), objTwitterFeed.ProfileId, objTwitterFeed.MessageId, objTwitterFeed.Feed, Network); } } } catch (Exception) { } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error("twtuser.GetStatuses_Home_Timeline ex.StackTrace >> " + ex.StackTrace); logger.Error("twtuser.GetStatuses_Home_Timeline ex.Message >> " + ex.Message); } #endregion }
public void getTwittwrDirectMessageRecieved(oAuthTwitter OAuth, string UserId) { #region Add Twitter Direct Message TwitterUser twtuser = new TwitterUser(); try { JArray Messages_Sent = twtuser.GetDirect_Messages(OAuth, 20); objTwitterDirectMessages = new Domain.Socioboard.Domain.TwitterDirectMessages(); foreach (var item in Messages_Sent) { objTwitterDirectMessages.UserId = Guid.Parse(UserId); objTwitterDirectMessages.Type = "twt_directmessages_received"; objTwitterDirectMessages.Id = Guid.NewGuid(); try { objTwitterDirectMessages.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterDirectMessages.CreatedDate = Utility.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"')); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterDirectMessages.Message = item["text"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterDirectMessages.RecipientId = item["recipient"]["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterDirectMessages.RecipientScreenName = item["recipient"]["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterDirectMessages.RecipientProfileUrl = item["recipient"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterDirectMessages.SenderId = item["sender"]["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterDirectMessages.SenderScreenName = item["sender"]["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterDirectMessages.SenderProfileUrl = item["sender"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterDirectMessages.EntryDate = DateTime.Now; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } if (!objTwitterDirectMessageRepository.checkExistsDirectMessages(objTwitterDirectMessages.MessageId)) { try { objTwitterDirectMessageRepository.addNewDirectMessage(objTwitterDirectMessages); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error("twtuser.GetDirect_Messages_Sent ex.StackTrace >> " + ex.StackTrace); logger.Error("twtuser.GetDirect_Messages_Sent ex.Message >> " + ex.Message); } #endregion }
public void getUserFeed(oAuthTwitter OAuth, string TwitterScreenName, string TwitterUserId, Guid userId) { try { //User user = (User)Session["LoggedUser"]; TwitterUser twtuser = new TwitterUser(); JArray data = twtuser.GetStatuses_Home_Timeline(OAuth); Domain.Socioboard.Domain.TwitterFeed objTwitterFeed; TwitterFeedRepository twtmsgrepo = new TwitterFeedRepository(); //TwitterFeed twtmsg = new TwitterFeed(); foreach (var item in data) { objTwitterFeed = new Domain.Socioboard.Domain.TwitterFeed(); objTwitterFeed.UserId = userId; objTwitterFeed.Type = "twt_feeds"; try { objTwitterFeed.Feed = item["text"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.SourceUrl = item["source"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.ScreenName = TwitterScreenName; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.ProfileId = TwitterUserId; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.FeedDate = Utility.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"')); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.InReplyToStatusUserId = item["in_reply_to_status_id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.Id = Guid.NewGuid(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.FromProfileUrl = item["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.FromName = item["user"]["name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterFeed.FromId = item["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } objTwitterFeed.EntryDate = DateTime.Now; try { objTwitterFeed.FromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } // Edited by Antima[20/12/2014] SentimentalAnalysis _SentimentalAnalysis = new SentimentalAnalysis(); FeedSentimentalAnalysisRepository _FeedSentimentalAnalysisRepository = new FeedSentimentalAnalysisRepository(); try { if (_FeedSentimentalAnalysisRepository.checkFeedExists(objTwitterFeed.ProfileId.ToString(), userId, objTwitterFeed.Id.ToString())) { if (!string.IsNullOrEmpty(objTwitterFeed.Feed)) { string Network = "twitter"; _SentimentalAnalysis.GetPostSentimentsFromUclassify(userId, objTwitterFeed.ProfileId, objTwitterFeed.MessageId, objTwitterFeed.Feed, Network); } } } catch (Exception) { } if (!twtmsgrepo.checkTwitterFeedExists(objTwitterFeed.ProfileId, objTwitterFeed.UserId, objTwitterFeed.MessageId)) { twtmsgrepo.addTwitterFeed(objTwitterFeed); } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
public void getUserTweets(oAuthTwitter OAuth, string TwitterScreenName, string TwitterUserId, Guid userId, Domain.Socioboard.Domain.TwitterAccount objTwitterAccount) { try { Users userinfo = new Users(); TwitterUser twtuser = new TwitterUser(); JArray data = twtuser.GetStatuses_User_Timeline(OAuth); TwitterMessageRepository twtmsgrepo = new TwitterMessageRepository(); // TwitterMessage twtmsg = new TwitterMessage(); Domain.Socioboard.Domain.TwitterMessage ObjTwitterMessage = new Domain.Socioboard.Domain.TwitterMessage(); foreach (var item in data) { ObjTwitterMessage.UserId = userId; ObjTwitterMessage.Type = "twt_usertweets"; try { ObjTwitterMessage.TwitterMsg = item["text"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.SourceUrl = item["source"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.ScreenName = TwitterScreenName; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.ProfileId = TwitterUserId; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.MessageDate = Utility.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"')); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.InReplyToStatusUserId = item["in_reply_to_status_id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.Id = Guid.NewGuid(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.FromProfileUrl = item["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.FromName = item["user"]["name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { ObjTwitterMessage.FromId = item["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } ObjTwitterMessage.EntryDate = DateTime.Now; try { ObjTwitterMessage.FromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } if (!twtmsgrepo.checkTwitterMessageExists(ObjTwitterMessage.ProfileId, ObjTwitterMessage.UserId, ObjTwitterMessage.MessageId)) { twtmsgrepo.addTwitterMessage(ObjTwitterMessage); } #region Add TwitterFollowerCount TwitterAccountFollowersRepository objTwitterAccountFollowersRepository = new TwitterAccountFollowersRepository(); Domain.Socioboard.Domain.TwitterAccountFollowers objTwitterAccountFollowers = new Domain.Socioboard.Domain.TwitterAccountFollowers(); objTwitterAccountFollowers.Id = Guid.NewGuid(); objTwitterAccountFollowers.UserId = userId; objTwitterAccountFollowers.EntryDate = DateTime.Now; objTwitterAccountFollowers.ProfileId = TwitterUserId; JArray profile = userinfo.Get_Users_LookUp_ByScreenName(OAuth, TwitterScreenName); foreach (var item_followerdata in profile) { try { objTwitterAccountFollowers.FollowingsCount = Convert.ToInt32(item_followerdata["friends_count"].ToString()); } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objTwitterAccountFollowers.FollowersCount = Convert.ToInt32(item_followerdata["followers_count"].ToString()); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } objTwitterAccountFollowersRepository.addTwitterAccountFollower(objTwitterAccountFollowers); #endregion } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
public void getMentions(oAuthTwitter oauth,TwitterAccount twitterAccount,Guid userid) { TwitterUser twtuser = new TwitterUser(); TimeLine tl = new TimeLine(); JArray data = tl.Get_Statuses_Mentions_Timeline(oauth); TwitterMessageRepository twtmsgrepo = new TwitterMessageRepository(); TwitterMessage twtmsg = new TwitterMessage(); foreach (var item in data) { twtmsg.UserId = userid; twtmsg.Type = "twt_mentions"; twtmsg.Id = Guid.NewGuid(); try { twtmsg.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.MessageDate = SocioBoard.Helper.Extensions.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"')); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.TwitterMsg = item["text"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.FromId = item["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.FromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.FromProfileUrl = item["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.InReplyToStatusUserId = item["in_reply_to_status_id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.SourceUrl = item["source"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.ProfileId = twitterAccount.TwitterUserId; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.ScreenName = item["user"]["screen_name"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twtmsg.EntryDate = DateTime.Now; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } if (!twtmsgrepo.checkTwitterMessageExists(twtmsg.MessageId)) { twtmsgrepo.addTwitterMessage(twtmsg); } } }