public string AddTwitterAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string requestToken, string requestSecret, string requestVerifier) { try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; string ret = string.Empty; GlobusTwitterLib.Twitter.Core.UserMethods.Users userinfo = new GlobusTwitterLib.Twitter.Core.UserMethods.Users(); oAuthTwitter OAuth = new oAuthTwitter(client_id, client_secret, redirect_uri); OAuth.AccessToken = requestToken; OAuth.AccessTokenSecret = requestVerifier; OAuth.AccessTokenGet(requestToken, requestVerifier); JArray profile = userinfo.Get_Users_LookUp_ByScreenName(OAuth, OAuth.TwitterScreenName); if (profile != null) { logger.Error("Twitter.asmx >> AddTwitterAccount >> Twitter profile : " + profile); } else { logger.Error("Twitter.asmx >> AddTwitterAccount >> NULL Twitter profile : " + profile); } objTwitterAccount = new Domain.Myfashion.Domain.TwitterAccount(); TwitterUser twtuser; foreach (var item in profile) { #region Add Twitter Account try { objTwitterAccount.FollowingCount = Convert.ToInt32(item["friends_count"].ToString()); } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objTwitterAccount.FollowersCount = Convert.ToInt32(item["followers_count"].ToString()); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } objTwitterAccount.Id = Guid.NewGuid(); objTwitterAccount.IsActive = true; objTwitterAccount.OAuthSecret = OAuth.AccessTokenSecret; objTwitterAccount.OAuthToken = OAuth.AccessToken; try { objTwitterAccount.ProfileImageUrl = item["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterAccount.ProfileUrl = string.Empty; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objTwitterAccount.TwitterUserId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception er) { try { objTwitterAccount.TwitterUserId = item["id"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { logger.Error(ex.StackTrace); } Console.WriteLine(er.StackTrace); } try { objTwitterAccount.TwitterScreenName = item["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { logger.Error(ex.StackTrace); } objTwitterAccount.UserId = Guid.Parse(UserId); #endregion if (!objTwitterAccountRepository.checkTwitterUserExists(objTwitterAccount.TwitterUserId, Guid.Parse(UserId))) { objTwitterAccountRepository.addTwitterkUser(objTwitterAccount); #region Add TeamMemberProfile Domain.Myfashion.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId)); Domain.Myfashion.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Myfashion.Domain.TeamMemberProfile(); objTeamMemberProfile.Id = Guid.NewGuid(); objTeamMemberProfile.TeamId = objTeam.Id; objTeamMemberProfile.Status = 1; objTeamMemberProfile.ProfileType = "twitter"; objTeamMemberProfile.StatusUpdateDate = DateTime.Now; objTeamMemberProfile.ProfileId = objTwitterAccount.TwitterUserId; objTeamMemberProfile.ProfileName = objTwitterAccount.TwitterScreenName; objTeamMemberProfile.ProfilePicUrl = objTwitterAccount.ProfileImageUrl; objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); #endregion #region SocialProfile Domain.Myfashion.Domain.SocialProfile objSocialProfile = new Domain.Myfashion.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "twitter"; objSocialProfile.ProfileId = objTwitterAccount.TwitterUserId; objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; #endregion #region Add Twitter Stats if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } objTwitterStats = new Domain.Myfashion.Domain.TwitterStats(); Random rNum = new Random(); objTwitterStats.Id = Guid.NewGuid(); objTwitterStats.TwitterId = objTwitterAccount.TwitterUserId; objTwitterStats.UserId = Guid.Parse(UserId); objTwitterStats.FollowingCount = objTwitterAccount.FollowingCount; objTwitterStats.FollowerCount = objTwitterAccount.FollowersCount; objTwitterStats.Age1820 = rNum.Next(objTwitterAccount.FollowersCount); objTwitterStats.Age2124 = rNum.Next(objTwitterAccount.FollowersCount); objTwitterStats.Age2534 = rNum.Next(objTwitterAccount.FollowersCount); objTwitterStats.Age3544 = rNum.Next(objTwitterAccount.FollowersCount); objTwitterStats.Age4554 = rNum.Next(objTwitterAccount.FollowersCount); objTwitterStats.Age5564 = rNum.Next(objTwitterAccount.FollowersCount); objTwitterStats.Age65 = rNum.Next(objTwitterAccount.FollowersCount); objTwitterStats.EntryDate = DateTime.Now; if (!objTwtstats.checkTwitterStatsExists(objTwitterAccount.TwitterUserId, Guid.Parse(UserId))) { objTwtstats.addTwitterStats(objTwitterStats); } #endregion #region AddTwitterFollowerCount Domain.Myfashion.Domain.TwitterAccountFollowers objTwitterAccountFollowers = new Domain.Myfashion.Domain.TwitterAccountFollowers(); TwitterAccountFollowersRepository objTwitterAccountFollowersRepository = new TwitterAccountFollowersRepository(); objTwitterAccountFollowers.Id = Guid.NewGuid(); objTwitterAccountFollowers.UserId = Guid.Parse(UserId); objTwitterAccountFollowers.EntryDate = DateTime.Now; objTwitterAccountFollowers.FollowingsCount = Convert.ToInt32(item["friends_count"].ToString()); objTwitterAccountFollowers.FollowersCount = Convert.ToInt32(item["followers_count"].ToString()); try { objTwitterAccountFollowers.ProfileId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception er) { try { objTwitterAccountFollowers.ProfileId = item["id"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { logger.Error(ex.StackTrace); } Console.WriteLine(er.StackTrace); } objTwitterAccountFollowersRepository.addTwitterAccountFollower(objTwitterAccountFollowers); #endregion ret = "Account Added Successfully"; } else { ret = "Account already Exist !"; } } getTwitterMessages(UserId, OAuth); getUserRetweets(UserId, OAuth); //edited by avinash[24-03-15] getTwitterEngagement(UserId, OAuth); getUserTweets(UserId, OAuth); getTwitterFeeds(UserId, OAuth); getTwitterDirectMessageSent(UserId, OAuth); getTwittwrDirectMessageRecieved(OAuth,UserId); getUserMentions(OAuth, objTwitterAccount.TwitterUserId, Guid.Parse(UserId)); getUserFollowers(OAuth, objTwitterAccount.TwitterScreenName, objTwitterAccount.TwitterUserId, Guid.Parse(UserId)); getUserRetweet(OAuth, objTwitterAccount.TwitterUserId, Guid.Parse(UserId)); //return ret; return new JavaScriptSerializer().Serialize(objTwitterAccount); } catch (Exception ex) { logger.Error(ex.StackTrace); return ""; } }
public void getUserTweets(oAuthTwitter OAuth, string TwitterScreenName, string TwitterUserId, Guid userId, Domain.Myfashion.Domain.TwitterAccount objTwitterAccount) { int I = 0; try { GlobusTwitterLib.Twitter.Core.UserMethods.Users userinfo = new GlobusTwitterLib.Twitter.Core.UserMethods.Users(); TwitterUser twtuser = new TwitterUser(); JArray data = twtuser.GetStatuses_User_Timeline(OAuth); TwitterMessageRepository twtmsgrepo = new TwitterMessageRepository(); // TwitterMessage twtmsg = new TwitterMessage(); Domain.Myfashion.Domain.TwitterMessage ObjTwitterMessage = new Domain.Myfashion.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)) { I++; twtmsgrepo.addTwitterMessage(ObjTwitterMessage); logger.Error("getUserTweetsCount>>>"+I); } #region Add TwitterFollowerCount TwitterAccountFollowersRepository objTwitterAccountFollowersRepository = new TwitterAccountFollowersRepository(); Domain.Myfashion.Domain.TwitterAccountFollowers objTwitterAccountFollowers = new Domain.Myfashion.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); } }