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");
     }
 }
        public bool AddFacebookFriendsGender(string ProfileId, string FacebookUserId)
        {
            Api.Myfashionmarketer.Models.FacebookAccount _FacebookAccount = new FacebookAccount();
            Domain.Myfashion.Domain.FacebookAccount      _facebookAccount = new Domain.Myfashion.Domain.FacebookAccount();

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

            if (string.IsNullOrEmpty(_facebookAccount.AccessToken))
            {
                _facebookAccount = new Domain.Myfashion.Domain.FacebookAccount();
                Api.Myfashionmarketer.Models.FacebookAccountRepository _FacebookAccountRepository = new FacebookAccountRepository();

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

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

            Domain.Myfashion.Domain.FacebookStats objfbStats = new Domain.Myfashion.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);
        }
 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";
     }
 }
Beispiel #4
0
        public string contactSearchFacebook(string keyword)
        {
            List <Domain.Myfashion.Domain.DiscoverySearch> lstDiscoverySearch = new List <Domain.Myfashion.Domain.DiscoverySearch>();
            string profileid = string.Empty;

            try
            {
                FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
                List <Domain.Myfashion.Domain.FacebookAccount> asltFbAccount = fbAccRepo.getFbAccounts();
                string accesstoken = string.Empty;
                foreach (Domain.Myfashion.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.Myfashion.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"));
            }
        }