Exemple #1
0
 public string GetAllFacebookAccounts()
 {
     try
     {
         FacebookAccountRepository objFbRepo = new FacebookAccountRepository();
         ArrayList lstFBAcc = objFbRepo.getAllFacebookAccounts();
         return(new JavaScriptSerializer().Serialize(lstFBAcc));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
         return("Something Went Wrong");
     }
 }
Exemple #2
0
        public string GetAllFacebookAccounts()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = 2147483647;
            try
            {
                FacebookAccountRepository objFbRepo = new FacebookAccountRepository();
                List <Domain.Socioboard.Domain.FacebookAccount> lstFBAcc = objFbRepo.GetAllFacebookAccounts();
                return(serializer.Serialize(lstFBAcc));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return(serializer.Serialize(new List <Domain.Socioboard.Domain.FacebookAccount>()));
            }
        }
        public string contactSearchFacebook(string keyword)
        {
            List <Domain.Socioboard.Domain.DiscoverySearch> lstDiscoverySearch = new List <Domain.Socioboard.Domain.DiscoverySearch>();
            string profileid = string.Empty;

            try
            {
                FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
                List <Domain.Socioboard.Domain.FacebookAccount> asltFbAccount = fbAccRepo.getFbAccounts();
                string accesstoken = string.Empty;
                foreach (Domain.Socioboard.Domain.FacebookAccount item in asltFbAccount)
                {
                    try
                    {
                        FacebookClient fb = new FacebookClient();
                        fb.AccessToken = item.AccessToken;

                        dynamic me = fb.Get("v2.0/me");
                        string  id = me["id"].ToString();
                        accesstoken = item.AccessToken;
                        break;
                    }
                    catch (Exception ex)
                    {
                    }
                }
                //string facebookSearchUrl = "https://graph.facebook.com/search?q=" + keyword + " &type=post&access_token=" + accesstoken + "&limit=100";
                string facebookSearchUrl = "https://graph.facebook.com/search?q=" + keyword + " &limit=20&type=user&access_token=" + accesstoken;
                var    facerequest       = (HttpWebRequest)WebRequest.Create(facebookSearchUrl);
                facerequest.Method = "GET";
                string outputface = string.Empty;
                using (var response = facerequest.GetResponse())
                {
                    using (var stream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252)))
                    {
                        outputface = stream.ReadToEnd();
                    }
                }
                if (!outputface.StartsWith("["))
                {
                    outputface = "[" + outputface + "]";
                }
                JArray facebookSearchResult = JArray.Parse(outputface);
                foreach (var item in facebookSearchResult)
                {
                    var data = item["data"];

                    foreach (var chile in data)
                    {
                        try
                        {
                            objDiscoverySearch          = new Domain.Socioboard.Domain.DiscoverySearch();
                            objDiscoverySearch.FromId   = chile["id"].ToString();
                            objDiscoverySearch.FromName = chile["name"].ToString();
                            lstDiscoverySearch.Add(objDiscoverySearch);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }

                return(new JavaScriptSerializer().Serialize(lstDiscoverySearch));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return(new JavaScriptSerializer().Serialize("Please try Again"));
            }
        }
Exemple #4
0
 public string ProfilesConnected(string UserId)
 {
     try
     {
         Guid userid = Guid.Parse(UserId);
         SocialProfilesRepository socialRepo = new SocialProfilesRepository();
         List <Domain.Socioboard.Domain.SocialProfile> lstsocioprofile = socialRepo.getAllSocialProfilesOfUser(userid);
         List <profileConnected> lstProfile = new List <profileConnected>();
         foreach (Domain.Socioboard.Domain.SocialProfile sp in lstsocioprofile)
         {
             profileConnected pc = new profileConnected();
             pc.Id            = sp.Id;
             pc.ProfileDate   = sp.ProfileDate;
             pc.ProfileId     = sp.ProfileId;
             pc.ProfileStatus = sp.ProfileStatus;
             pc.ProfileType   = sp.ProfileType;
             pc.UserId        = sp.UserId;
             if (sp.ProfileType == "facebook")
             {
                 try
                 {
                     FacebookAccountRepository objFbAccRepo            = new FacebookAccountRepository();
                     Domain.Socioboard.Domain.FacebookAccount objFbAcc = objFbAccRepo.getUserDetails(sp.ProfileId);
                     pc.ProfileName   = objFbAcc.FbUserName;
                     pc.ProfileImgUrl = "http://graph.facebook.com/" + sp.ProfileId + "/picture?type=small";
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.StackTrace);
                 }
             }
             else if (sp.ProfileType == "twitter")
             {
                 try
                 {
                     TwitterAccountRepository objTwtAccRepo            = new TwitterAccountRepository();
                     Domain.Socioboard.Domain.TwitterAccount objTwtAcc = objTwtAccRepo.getUserInfo(sp.ProfileId);
                     pc.ProfileName   = objTwtAcc.TwitterScreenName;
                     pc.ProfileImgUrl = objTwtAcc.ProfileImageUrl;
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.StackTrace);
                 }
             }
             else if (sp.ProfileType == "instagram")
             {
                 try
                 {
                     InstagramAccountRepository objInsAccRepo            = new InstagramAccountRepository();
                     Domain.Socioboard.Domain.InstagramAccount objInsAcc = objInsAccRepo.getInstagramAccountById(sp.ProfileId);
                     pc.ProfileName   = objInsAcc.InsUserName;
                     pc.ProfileImgUrl = objInsAcc.ProfileUrl;
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.StackTrace);
                 }
             }
             else if (sp.ProfileType == "linkedin")
             {
                 try
                 {
                     LinkedInAccountRepository objLiAccRepo            = new LinkedInAccountRepository();
                     Domain.Socioboard.Domain.LinkedInAccount objLiAcc = objLiAccRepo.getLinkedinAccountDetailsById(sp.ProfileId);
                     pc.ProfileName   = objLiAcc.LinkedinUserName;
                     pc.ProfileImgUrl = objLiAcc.ProfileImageUrl;
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.StackTrace);
                 }
             }
             else if (sp.ProfileType == "googleplus")
             {
                 try
                 {
                     GooglePlusAccountRepository objGpAccRepo            = new GooglePlusAccountRepository();
                     Domain.Socioboard.Domain.GooglePlusAccount objGpAcc = objGpAccRepo.getUserDetails(sp.ProfileId);
                     pc.ProfileName   = objGpAcc.GpUserName;
                     pc.ProfileImgUrl = objGpAcc.GpProfileImage;
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.StackTrace);
                 }
             }
             else if (sp.ProfileType == "tumblr")
             {
                 try
                 {
                     TumblrAccountRepository objTumblrAccountRepository      = new TumblrAccountRepository();
                     Domain.Socioboard.Domain.TumblrAccount objTumblrAccount = objTumblrAccountRepository.getTumblrAccountDetailsById(sp.ProfileId);
                     pc.ProfileName   = objTumblrAccount.tblrUserName;
                     pc.ProfileImgUrl = objTumblrAccount.tblrProfilePicUrl;
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.StackTrace);
                 }
             }
             else if (sp.ProfileType == "youtube")
             {
                 try
                 {
                     YoutubeAccountRepository objYoutubeAccountRepository      = new YoutubeAccountRepository();
                     Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = objYoutubeAccountRepository.getYoutubeAccountDetailsById(sp.ProfileId);
                     pc.ProfileName   = objYoutubeAccount.Ytusername;
                     pc.ProfileImgUrl = objYoutubeAccount.Ytprofileimage;
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.StackTrace);
                 }
             }
             lstProfile.Add(pc);
         }
         return(new JavaScriptSerializer().Serialize(lstProfile));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
         return(new JavaScriptSerializer().Serialize("Please Try Again"));
     }
 }
 public string GetAllFacebookAccounts()
 {
     try
     {
         FacebookAccountRepository objFbRepo = new FacebookAccountRepository();
         ArrayList lstFBAcc = objFbRepo.getAllFacebookAccounts();
         return new JavaScriptSerializer().Serialize(lstFBAcc);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
         return "Something Went Wrong";
     }
 }
Exemple #6
0
        public string DiscoverySearchFacebook(string UserId, string keyword)
        {
            List <Domain.Socioboard.Domain.DiscoverySearch> lstDiscoverySearch = new List <Domain.Socioboard.Domain.DiscoverySearch>();
            string profileid = string.Empty;

            try
            {
                lstDiscoverySearch = dissearchrepo.GetAllSearchKeywordsByUserId(Guid.Parse(UserId), keyword, "facebook");
                if (lstDiscoverySearch.Count < 1)
                {
                    FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
                    ArrayList asltFbAccount             = fbAccRepo.getAllFacebookAccounts();
                    string    accesstoken = string.Empty;
                    foreach (Domain.Socioboard.Domain.FacebookAccount item in asltFbAccount)
                    {
                        accesstoken = item.AccessToken;
                        if (this.CheckFacebookToken(accesstoken, keyword))
                        {
                            break;
                        }
                    }
                    string facebookSearchUrl = "https://graph.facebook.com/v1.0/search?q=" + keyword + " &type=post&access_token=" + accesstoken + "&limit=100";
                    var    facerequest       = (HttpWebRequest)WebRequest.Create(facebookSearchUrl);
                    facerequest.Method = "GET";
                    string outputface = string.Empty;
                    using (var response = facerequest.GetResponse())
                    {
                        using (var stream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252)))
                        {
                            outputface = stream.ReadToEnd();
                        }
                    }
                    if (!outputface.StartsWith("["))
                    {
                        outputface = "[" + outputface + "]";
                    }
                    JArray facebookSearchResult = JArray.Parse(outputface);
                    foreach (var item in facebookSearchResult)
                    {
                        var data = item["data"];

                        foreach (var chile in data)
                        {
                            try
                            {
                                objDiscoverySearch                 = new Domain.Socioboard.Domain.DiscoverySearch();
                                objDiscoverySearch.CreatedTime     = DateTime.Parse(chile["created_time"].ToString());
                                objDiscoverySearch.EntryDate       = DateTime.Now;
                                objDiscoverySearch.FromId          = chile["from"]["id"].ToString();
                                objDiscoverySearch.FromName        = chile["from"]["name"].ToString();
                                objDiscoverySearch.ProfileImageUrl = "http://graph.facebook.com/" + chile["from"]["id"] + "/picture?type=small";
                                objDiscoverySearch.SearchKeyword   = keyword;
                                objDiscoverySearch.Network         = "facebook";
                                objDiscoverySearch.Message         = chile["message"].ToString();
                                objDiscoverySearch.MessageId       = chile["id"].ToString();
                                objDiscoverySearch.Id              = Guid.NewGuid();
                                objDiscoverySearch.UserId          = Guid.Parse(UserId);

                                string postURL = "https://www.facebook.com/" + objDiscoverySearch.MessageId;

                                if (!dissearchrepo.isKeywordPresent(objDiscoverySearch.SearchKeyword, objDiscoverySearch.MessageId))
                                {
                                    dissearchrepo.addNewSearchResult(objDiscoverySearch);
                                }
                                lstDiscoverySearch.Add(objDiscoverySearch);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.StackTrace);
                            }
                        }
                    }

                    return(new JavaScriptSerializer().Serialize(lstDiscoverySearch));
                }
                else
                {
                    return(new JavaScriptSerializer().Serialize(lstDiscoverySearch));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return(new JavaScriptSerializer().Serialize("Please try Again"));
            }
        }
        public string DiscoverySearchFacebook(string UserId, string keyword)
        {
            List <Domain.Socioboard.Domain.DiscoverySearch> lstDiscoverySearch = new List <Domain.Socioboard.Domain.DiscoverySearch>();
            string profileid = string.Empty;

            try
            {
                //  lstDiscoverySearch = dissearchrepo.GetAllSearchKeywordsByUserId(Guid.Parse(UserId), keyword, "facebook");

                FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
                ArrayList asltFbAccount             = fbAccRepo.getAllFacebookAccounts();
                string    accesstoken = string.Empty;

                #region Added Sumit Gupta [27/01/15]
                foreach (Domain.Socioboard.Domain.FacebookAccount item in asltFbAccount)
                {
                    accesstoken = item.AccessToken;
                    if (this.CheckFacebookToken(accesstoken, keyword))
                    {
                        break;
                    }
                }
                #endregion

                ////Access Token HARD CODED temporarily
                //accesstoken = "CAAKMrAl97iIBAD9MqfWtfjIxwFVteGCLVZBsoHpc1TZCH8Kf3KQuMebkbNYLb282cUTisu6iGZBiZAzzwxWvDhh20vCzs5mZCFZBblZBXu40BQisUjoOCZARUQklHBiK3Cx7DOgdXtbvupC4xJ1VpPjKspwiZBRzNYncjgQAyUqd5sGsXUDHcqKy0UBYkmbfq7QZCFgpyG5icOPeMhRb4TXJaic7UF7B1WHLhw2A5EW0kb3AZDZD";

                string facebookSearchUrl = "https://graph.facebook.com/search?q=" + keyword + " &type=post&access_token=" + accesstoken + "&limit=100";
                var    facerequest       = (HttpWebRequest)WebRequest.Create(facebookSearchUrl);
                facerequest.Method = "GET";
                string outputface = string.Empty;
                using (var response = facerequest.GetResponse())
                {
                    using (var stream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252)))
                    {
                        outputface = stream.ReadToEnd();
                    }
                }
                if (!outputface.StartsWith("["))
                {
                    outputface = "[" + outputface + "]";
                }
                JArray facebookSearchResult = JArray.Parse(outputface);
                foreach (var item in facebookSearchResult)
                {
                    var data = item["data"];

                    foreach (var chile in data)
                    {
                        try
                        {
                            objDiscoverySearch = new Domain.Socioboard.Domain.DiscoverySearch();
                            objDiscoverySearch.SearchKeyword = keyword;
                            objDiscoverySearch.Network       = "facebook";
                            objDiscoverySearch.Id            = Guid.NewGuid();
                            objDiscoverySearch.UserId        = Guid.Parse(UserId);

                            if (!dissearchrepo.isKeywordPresentforNetwork(objDiscoverySearch.SearchKeyword, objDiscoverySearch.Network))
                            {
                                dissearchrepo.addNewSearchResult(objDiscoverySearch);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                        try
                        {
                            Domain.Socioboard.Domain.DiscoverySearch objSearchHistory = new Domain.Socioboard.Domain.DiscoverySearch();
                            objSearchHistory.CreatedTime = DateTime.Parse(chile["created_time"].ToString());
                            objSearchHistory.EntryDate   = DateTime.Now;
                            objSearchHistory.FromId      = chile["from"]["id"].ToString();
                            try
                            {
                                objSearchHistory.FromName = chile["from"]["name"].ToString();
                            }
                            catch { }
                            try
                            {
                                objSearchHistory.ProfileImageUrl = "http://graph.facebook.com/" + chile["from"]["id"] + "/picture?type=small";
                            }
                            catch { }
                            objSearchHistory.SearchKeyword = keyword;
                            objSearchHistory.Network       = "facebook";
                            try
                            {
                                objSearchHistory.Message = chile["message"].ToString();
                            }
                            catch { }
                            try
                            {
                                objSearchHistory.MessageId = chile["id"].ToString();
                            }
                            catch { }
                            objSearchHistory.Id     = Guid.NewGuid();
                            objSearchHistory.UserId = Guid.Parse(UserId);
                            lstDiscoverySearch.Add(objSearchHistory);
                        }
                        catch { }
                    }
                }
                return(new JavaScriptSerializer().Serialize(lstDiscoverySearch));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return(new JavaScriptSerializer().Serialize("Please try Again"));
            }
        }
        public bool AddFacebookFriendsGender(string ProfileId, string FacebookUserId)
        {
            Api.Socioboard.Services.FacebookAccount  _FacebookAccount = new FacebookAccount();
            Domain.Socioboard.Domain.FacebookAccount _facebookAccount = new Domain.Socioboard.Domain.FacebookAccount();

            _facebookAccount = (Domain.Socioboard.Domain.FacebookAccount)(new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(_FacebookAccount.getFacebookAccountDetailsById(ProfileId, FacebookUserId), typeof(Domain.Socioboard.Domain.FacebookAccount)));

            if (string.IsNullOrEmpty(_facebookAccount.AccessToken))
            {
                _facebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                Api.Socioboard.Services.FacebookAccountRepository _FacebookAccountRepository = new FacebookAccountRepository();

                System.Collections.ArrayList lstFacebookAccounts = _FacebookAccountRepository.getAllFacebookAccounts();

                Random _random = new Random();
                var    rnum    = _random.Next(0, lstFacebookAccounts.Count - 1);
                _facebookAccount = (Domain.Socioboard.Domain.FacebookAccount)lstFacebookAccounts[rnum];
            }
            int malecount   = 0;
            int femalecount = 0;

            Domain.Socioboard.Domain.FacebookStats objfbStats = new Domain.Socioboard.Domain.FacebookStats();
            FacebookStatsRepository objFBStatsRepo            = new FacebookStatsRepository();

            FacebookClient fb = new FacebookClient();

            fb.AccessToken = _facebookAccount.AccessToken;
            try
            {
                dynamic data = fb.Get("v2.0/me/friends?fields=gender");

                //dynamic data, dynamic profile, Guid userId


                foreach (var item in data["data"])
                {
                    try
                    {
                        if (item["gender"] == "male")
                        {
                            malecount++;
                        }
                        else if (item["gender"] == "female")
                        {
                            femalecount++;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                return(false);
            }
            objfbStats.EntryDate   = DateTime.Now;
            objfbStats.FbUserId    = _facebookAccount.FbUserId;//profile["id"].ToString();
            objfbStats.FemaleCount = femalecount;
            objfbStats.Id          = Guid.NewGuid();
            objfbStats.MaleCount   = malecount;
            objfbStats.UserId      = _facebookAccount.UserId;
            objfbStats.FanCount    = getfanCount(objfbStats, _facebookAccount.AccessToken);

            if (objFBStatsRepo.checkFacebookStatsExists(objfbStats.FbUserId.ToString(), objfbStats.UserId, objfbStats.FanCount, objfbStats.MaleCount, objfbStats.FemaleCount))
            {
                objFBStatsRepo.addFacebookStats(objfbStats);
            }


            return(true);
        }