Exemple #1
0
        public void GetFacebookData(object userId)
        {
            Guid UserId = (Guid)userId;
            FacebookAccountRepository objFbRepo = new FacebookAccountRepository();
            FacebookHelper fbhelper = new FacebookHelper();
            ArrayList arrFbAcc = objFbRepo.getAllFacebookAccountsOfUser(UserId);
            foreach (FacebookAccount itemFb in arrFbAcc)
            {
                 FacebookHelper objFbHelper = new FacebookHelper();
                 FacebookInsightStatsHelper fbiHelper = new FacebookInsightStatsHelper();
                 try
                 {                  
                    FacebookClient fb = new FacebookClient();
                    fb.AccessToken = itemFb.AccessToken;

                    var feeds = fb.Get("/me/feed");
                    var home = fb.Get("me/home");
                    var profile = fb.Get("me");
                    getFacebookUserHome(home, profile, UserId);
                    getFacebookUserFeeds(feeds, profile, UserId);
                    getFacebookProfile(profile, UserId);
                    FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
                    try
                    {
                        int fancountacc = 0;
                        dynamic fanacccount = fb.Get("fql", new { q = "SELECT friend_count FROM user WHERE uid=" + itemFb.FbUserId });
                        foreach (var friend in fanacccount.data)
                        {
                            fancountacc = Convert.ToInt32(friend.friend_count);
                        }
                       
                        fbAccRepo.updateFriendsCount(itemFb.FbUserId, itemFb.UserId, fancountacc);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    if (itemFb.Type == "page")
                    {
                        try
                        {
                            fbiHelper.getFanPageLikesByGenderAge(itemFb.FbUserId, UserId, 10);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }

                        try
                        {
                            fbiHelper.getPageImpresion(itemFb.FbUserId, UserId, 10);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                                
                        }
                        try
                        {
                            fbiHelper.getStories(itemFb.FbUserId, UserId, 10);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        try
                        {
                            fbiHelper.getLocation(itemFb.FbUserId, UserId, 10);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        try
                        {
                            fbiHelper.getFanPost(itemFb.FbUserId, UserId, 10);
                        }
                        catch (Exception ex)
                        {
                        }

                        try
                        {
                            int fancountPage = 0;
                            dynamic fancount = fb.Get("fql", new { q = " SELECT fan_count FROM page WHERE page_id =" + itemFb.FbUserId });
                            foreach (var friend in fancount.data)
                            {
                                fancountPage = Convert.ToInt32(friend.fan_count);
                            }
                           // FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
                            fbAccRepo.updateFansCount(itemFb.FbUserId, itemFb.UserId, fancountPage);

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }

                    }
                  //  var friendsgenderstats = fb.Get("me/friends?fields=gender");
                   // fbhelper.getfbFriendsGenderStats(friendsgenderstats, profile, UserId);
                }
                catch (Exception Err)
                {
                    Console.Write(Err.Message);
                }
            }
        }