예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="id"></param>
        /// <param name="timeInterVal"></param>
        public static void SchedulePagePost(string accessToken, string destinationPageId, string sourcePageId, int timeInterVal)
        {
            try
            {
                var timeIncrementer = 1;

                var cursorNext = string.Empty;
                do
                {
                    var feeds = Fbpages.getFacebookPageRecentPost(accessToken, sourcePageId, cursorNext);

                    if (string.IsNullOrEmpty(feeds) || feeds.Equals("[]"))
                    {
                        continue;
                    }

                    var fbPageNotes = JObject.Parse(feeds);
                    try
                    {
                        cursorNext = fbPageNotes["paging"]["next"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        cursorNext = "0";
                    }
                    foreach (var obj in JArray.Parse(fbPageNotes["data"].ToString()))
                    {
                        try
                        {
                            var postId = obj["id"].ToString();
                            postId = postId.Split('_')[1];

                            var timestamp = DateExtension.ConvertToUnixTimestamp(DateTime.UtcNow.AddMinutes(timeInterVal * timeIncrementer));
                            var link      = "https://www.facebook.com/" + sourcePageId + "/posts/" + postId;

                            var pageAccessToken =
                                FacebookApiHelper.GetPageAccessToken(destinationPageId, accessToken, string.Empty);

                            var status = FacebookApiHelper.PublishPostOnSchedule(string.Empty, accessToken, destinationPageId,
                                                                                 link, timestamp.ToString(CultureInfo.InvariantCulture));

                            if (status)
                            {
                                timeIncrementer++;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                } while (cursorNext != "0");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public IActionResult ReconnFacebookPages(long userId, long groupId, string accessToken)
        {
            int     invalidaccessToken = 0;
            dynamic profile            = Fbpages.getFbPageData(accessToken);
            string  subscribed_apps    = Fbpages.subscribed_apps(accessToken, Convert.ToString(profile["id"]));

            try
            {
                string x = Convert.ToString(profile);
                _logger.LogError(x);
            }
            catch { }
            if (Convert.ToString(profile) == "Invalid Access Token")
            {
                invalidaccessToken++;
            }
            else
            {
                DatabaseRepository dbr = new DatabaseRepository(_logger, _env);
                Domain.Socioboard.Models.Facebookaccounts fbacc = Api.Socioboard.Repositories.FacebookRepository.getFacebookAccount(Convert.ToString(profile["id"]), _redisCache, dbr);

                int isSaved = 0;
                if (fbacc != null)
                {
                    fbacc.IsActive           = true;
                    fbacc.UserId             = userId;
                    fbacc.Is90DayDataUpdated = false;
                    try
                    {
                        fbacc.Friends = (Convert.ToInt64(profile["fan_count"]));
                    }
                    catch (Exception)
                    {
                        fbacc.Friends = 0;
                    }
                    try
                    {
                        fbacc.coverPic = (Convert.ToString(profile["cover"]["source"]));
                    }
                    catch (Exception)
                    {
                    }
                    fbacc.AccessToken = accessToken;
                    isSaved           = dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(fbacc);
                    if (isSaved > 0)
                    {
                        return(Ok("Page Reconnected Successfully"));
                    }
                    else
                    {
                        return(Ok("some thing went wrong"));
                    }
                }
            }
            return(Ok("Page reconnect successfully"));
        }
예제 #3
0
        public string GetFacebookPageDetails(string ProfileId, string AccessToken)
        {
            dynamic pagedata = Fbpages.GetFbPageData(AccessToken);

            int    fancount = Convert.ToInt16(pagedata["fan_count"]);
            string pageNmae = Convert.ToString(pagedata["name"]);

            ///string facebookpageUrl = "https://graph.facebook.com/v2.5/" + ProfileId + "?access_token=" + AccessToken +"?fan_count";
            // string outputfacepageUrl = getFacebookResponse(facebookpageUrl);
            //JObject pageobj = JObject.Parse(outputfacepageUrl);
            return(Convert.ToString(pagedata["fan_count"]));// outputfacepageUrl;
        }
        public IActionResult AddFacebookPages(long userId, long groupId)
        {
            string data = Request.Form["profileaccesstoken"];

            string[] accesstoken    = data.Split(',');
            int      addedPageCount = 0;

            foreach (var item in accesstoken)
            {
                dynamic profile = Fbpages.getFbPageData(item);
                // string subscribed_apps= Fbpages.subscribed_apps(item, Convert.ToString(profile["id"]));
                try
                {
                    string x = Convert.ToString(profile);
                    _logger.LogError(x);
                }
                catch { }
                if (Convert.ToString(profile) == "Invalid Access Token")
                {
                    return(Ok("Invalid Access Token"));
                }
                DatabaseRepository dbr = new DatabaseRepository(_logger, _env);
                Domain.Socioboard.Models.Facebookaccounts fbacc = Api.Socioboard.Repositories.FacebookRepository.getFacebookAccount(Convert.ToString(profile["id"]), _redisCache, dbr);
                if (fbacc != null && fbacc.IsActive == true)
                {
                    addedPageCount++;
                    //return Ok("Facebook Page added by other user.");
                }
                else
                {
                    Groups ngrp = dbr.Find <Domain.Socioboard.Models.Groups>(t => t.adminId == userId && t.id == groupId).FirstOrDefault();
                    if (ngrp == null)
                    {
                        return(Ok("Wrong Group Id"));
                    }
                    // Adding Facebook Page
                    int res = Api.Socioboard.Repositories.FacebookRepository.AddFacebookPage(profile, dbr, userId, ngrp.id, Domain.Socioboard.Enum.FbProfileType.FacebookPage, item, _redisCache, _appSettings, _logger);
                }
            }
            if (addedPageCount == accesstoken.Length)
            {
                return(Ok("Facebook Page added by other user."));
            }
            else if (addedPageCount > 0)
            {
                return(Ok("Pages added successfully and " + addedPageCount + " pages added by other user"));
            }
            return(Ok("Page added successfully"));
        }
        public static void schedulePage_Post(string accessToken, string id, int TimeInterVal)
        {
            try
            {
                int    i           = 1;
                string curser_next = string.Empty;
                do
                {
                    string feeds  = Fbpages.getFacebookPageRecentPost(accessToken, id, curser_next);
                    string feedId = string.Empty;

                    if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]"))
                    {
                        JObject fbpageNotes = JObject.Parse(feeds);
                        try
                        {
                            curser_next = fbpageNotes["paging"]["next"].ToString();
                        }
                        catch (Exception ex)
                        {
                            curser_next = "0";
                        }
                        foreach (JObject obj in JArray.Parse(fbpageNotes["data"].ToString()))
                        {
                            try
                            {
                                string feedid = obj["id"].ToString();
                                feedid = feedid.Split('_')[1];
                                double timestamp = Helper.DateExtension.ConvertToUnixTimestamp(DateTime.UtcNow.AddMinutes(TimeInterVal * i));
                                string link      = "https://www.facebook.com/" + id + "/posts/" + feedid;
                                string ret       = Fbpages.schedulePage_Post(accessToken, link, timestamp.ToString());
                                if (!string.IsNullOrEmpty(ret))
                                {
                                    i++;
                                }
                            }
                            catch { }
                        }
                    }
                } while (curser_next != "0");
            }
            catch (Exception ex)
            {
            }
        }
예제 #6
0
        public static int updateFacebookPageFeeds(Domain.Socioboard.Models.Facebookaccounts fbAcc)
        {
            apiHitsCount = 0;
            Model.DatabaseRepository dbr = new DatabaseRepository();

            if (fbAcc.LastUpdate.AddHours(1) <= DateTime.UtcNow)
            {
                if (fbAcc.IsAccessTokenActive)
                {
                    dynamic profile = Fbpages.getFbPageData(fbAcc.AccessToken);
                    apiHitsCount++;
                    if (Convert.ToString(profile) != "Invalid Access Token")
                    {
                        try
                        {
                            fbAcc.Friends = (Convert.ToInt64(profile["fan_count"]));
                        }
                        catch (Exception)
                        {
                            fbAcc.Friends = fbAcc.Friends;
                        }

                        try
                        {
                            dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(fbAcc);
                        }
                        catch { }
                        while (apiHitsCount < MaxapiHitsCount)
                        {
                            SaveFacebookFeeds(fbAcc.AccessToken, fbAcc.FbUserId, fbAcc.FbUserName);
                            SavePageConversations(fbAcc.AccessToken, fbAcc.FbUserId);
                            SaveFacebookPageFeed(fbAcc.AccessToken, fbAcc.FbUserId, fbAcc.FbUserName);
                            // SavePageNotification(fbAcc.AccessToken, fbAcc.FbUserId);
                        }
                    }
                }
            }
            else
            {
                apiHitsCount = 0;
            }
            return(0);
        }
 public IActionResult GetFacebookPages(string accesstoken, long groupId)
 {
     try
     {
         List <Domain.Socioboard.Models.Facebookpage> lstpages = new List <Facebookpage>();
         lstpages = Fbpages.Getfacebookpages(accesstoken);
         DatabaseRepository dbr = new DatabaseRepository(_logger, _env);
         List <Domain.Socioboard.Models.Groupprofiles> lstGrpProfiles = Repositories.GroupProfilesRepository.getGroupProfiles(groupId, _redisCache, dbr);
         lstGrpProfiles = lstGrpProfiles.Where(t => t.profileType == Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage).ToList();
         string[] lstStr = lstGrpProfiles.Select(t => t.profileId).ToArray();
         if (lstStr.Length > 0)
         {
             lstpages.Where(t => lstStr.Contains(t.ProfilePageId)).Select(s => { s.connected = 1; return(s); }).ToList();
         }
         return(Ok(lstpages));
     }
     catch (Exception ex)
     {
         _logger.LogError("GetFacebookPages" + ex.StackTrace);
         _logger.LogError("GetFacebookPages" + ex.Message);
         return(Ok(new List <Domain.Socioboard.Models.Facebookpage>()));
     }
 }
예제 #8
0
        public static int updateFacebookPageFeeds(Domain.Socioboard.Models.Facebookaccounts fbAcc)
        {
            apiHitsCount = 0;
            Model.DatabaseRepository dbr = new DatabaseRepository();

            if (fbAcc.LastUpdate.AddHours(1) <= DateTime.UtcNow)
            {
                if (fbAcc.IsAccessTokenActive)
                {
                    dynamic profile = Fbpages.getFbPageData(fbAcc.AccessToken);
                    if (fbAcc.FbPageSubscription == Domain.Socioboard.Enum.FbPageSubscription.NotSubscribed)
                    {
                        string subscribed_apps = Fbpages.subscribed_apps(fbAcc.AccessToken, Convert.ToString(profile["id"]));
                        fbAcc.FbPageSubscription = Domain.Socioboard.Enum.FbPageSubscription.Subscribed;
                    }
                    apiHitsCount++;
                    if (Convert.ToString(profile) != "Invalid Access Token")
                    {
                        try
                        {
                            fbAcc.Friends = (Convert.ToInt64(profile["fan_count"]));
                        }
                        catch (Exception)
                        {
                            fbAcc.Friends = fbAcc.Friends;
                        }

                        try
                        {
                            fbAcc.EmailId = (Convert.ToString(profile["emails"]));
                            fbAcc.EmailId = fbAcc.EmailId.Replace("[", "").Replace("]", "").Replace("\"", "");
                        }
                        catch (Exception)
                        {
                            fbAcc.EmailId = fbAcc.EmailId;
                        }

                        try
                        {
                            fbAcc.coverPic = (Convert.ToString(profile["cover"]["source"]));
                        }
                        catch (Exception)
                        {
                        }
                        try
                        {
                            dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(fbAcc);
                        }
                        catch { }
                        while (apiHitsCount < MaxapiHitsCount)
                        {
                            SaveFacebookFeeds(fbAcc.AccessToken, fbAcc.FbUserId, fbAcc.FbUserName);
                            SavePageConversations(fbAcc.AccessToken, fbAcc.FbUserId);
                            SaveFacebookPageFeed(fbAcc.AccessToken, fbAcc.FbUserId, fbAcc.FbUserName);
                            SaveFacebookPagePromotionalDetails(fbAcc.AccessToken, fbAcc.FbUserId);
                            SaveFacebookPageTaggedDetails(fbAcc.AccessToken, fbAcc.FbUserId);
                            // SavePageNotification(fbAcc.AccessToken, fbAcc.FbUserId);
                        }
                    }
                }
            }
            else
            {
                apiHitsCount = 0;
            }
            return(0);
        }
예제 #9
0
        public void Groupshreathon(object o)
        {
            try
            {
                var arr                  = o as object[];
                var shareathon           = (GroupShareathon)arr[0];
                var dbr                  = (DatabaseRepository)arr[1];
                var shareathonRepository = (MongoRepository)arr[2];
                var ids                  = shareathon.Facebookpageid.Split(',');

                foreach (var id in ids)
                {
                    try
                    {
                        var groupApiHitsCountNew = 0;
                        var fbAcc = dbr.Single <Facebookaccounts>(t => t.FbUserId == shareathon.Facebookaccountid);
                        //var lstFbAcc = dbr.Single<Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == id);

                        if (fbAcc != null)
                        {
                            if (groupApiHitsCountNew < GroupMaxapiHitsCount)
                            {
                                var feeds = string.Empty;
                                if (fbAcc.GroupShareathonUpdate.AddHours(1) <= DateTime.UtcNow)
                                {
                                    feeds = Fbpages.getFacebookRecentPost(fbAcc.AccessToken, id);

                                    var feedId = string.Empty;
                                    if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]"))
                                    {
                                        var fbpageNotes = JObject.Parse(feeds);
                                        foreach (var obj in JArray.Parse(fbpageNotes["data"].ToString()))
                                        {
                                            try
                                            {
                                                var feedid = obj["id"].ToString();
                                                feedid = feedid.Split('_')[1];
                                                feedId = feedid + "," + feedId;
                                            }
                                            catch (Exception ex)
                                            {
                                                Console.WriteLine(ex.Message);
                                            }
                                        }

                                        try
                                        {
                                            var dt = SBHelper.ConvertFromUnixTimestamp(shareathon.Lastsharetimestamp);
                                            dt = dt.AddMinutes(shareathon.Timeintervalminutes);
                                            if (shareathon.Lastpostid == null ||
                                                !shareathon.Lastpostid.Equals(feedId) &&
                                                SBHelper.ConvertToUnixTimestamp(dt) <=
                                                SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow))
                                            {
                                                ShareFeedonGroup(fbAcc.AccessToken, feedId, id, "",
                                                                 shareathon.Facebookgroupid, shareathon.Timeintervalminutes,
                                                                 shareathon.Facebookaccountid, shareathon.Lastsharetimestamp,
                                                                 shareathon.Facebooknameid);
                                            }
                                            fbAcc.GroupShareathonUpdate = DateTime.UtcNow;
                                            dbr.Update(fbAcc);
                                        }
                                        catch (Exception ex)
                                        {
                                            Console.WriteLine(ex.Message);
                                        }
                                    }
                                    else
                                    {
                                        FilterDefinition <BsonDocument> filter =
                                            new BsonDocument("strId", shareathon.strId);
                                        var update = Builders <BsonDocument> .Update.Set("FacebookStatus", 0);

                                        shareathonRepository.Update <GroupShareathon>(update, filter);
                                        GroupapiHitsCount = GroupMaxapiHitsCount;
                                    }
                                }
                                else
                                {
                                    GroupapiHitsCount = 0;
                                }
                            }
                        }
                    }
                    catch
                    {
                        GroupapiHitsCount = GroupMaxapiHitsCount;
                    }
                }
            }
            catch (Exception e)
            {
                GroupapiHitsCount = GroupMaxapiHitsCount;
                Console.WriteLine(e.Message);
            }
            finally
            {
                NoOfthreadGroupshreathonRunning--;
            }
        }
예제 #10
0
        public void PageShreathon(object o)
        {
            try
            {
                var arr        = o as object[];
                var shareathon = (PageShareathon)arr[0];
                var dbr        = (DatabaseRepository)arr[1];

                var shareathonRepository = (MongoRepository)arr[2];

                var ids = shareathon.Facebookpageid.Split(',');
                GlobalVariable.pageShareathonIdsRunning.Add(shareathon.strId);

                foreach (var id in ids)
                {
                    try
                    {
                        PageapiHitsCount = 0;
                        var fbAcc = dbr.Single <Facebookaccounts>(t => t.FbUserId == shareathon.Facebookaccountid);
                        Facebookaccounts facebookPage = null;

                        var lstFbAcc = dbr.Single <Facebookaccounts>(t => t.FbUserId == id);

                        if (lstFbAcc != null)
                        {
                            facebookPage = lstFbAcc;
                        }
                        if (facebookPage != null)
                        {
                            if (PageapiHitsCount < PageMaxapiHitsCount)
                            {
                                var feeds = string.Empty;

                                if (facebookPage.PageShareathonUpdate.AddHours(1) <= DateTime.UtcNow)
                                {
                                    feeds = Fbpages.getFacebookRecentPost(fbAcc.AccessToken, facebookPage.FbUserId);
                                    var feedId = string.Empty;

                                    if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]"))
                                    {
                                        PageapiHitsCount++;
                                        var fbpageNotes = JObject.Parse(feeds);

                                        foreach (var obj in JArray.Parse(fbpageNotes["data"].ToString()))
                                        {
                                            try
                                            {
                                                feedId = obj["id"].ToString();
                                                feedId = feedId.Split('_')[1];
                                                var dt = SBHelper.ConvertFromUnixTimestamp(
                                                    shareathon.Lastsharetimestamp);
                                                dt = dt.AddMinutes(shareathon.Timeintervalminutes);

                                                if (!shareathon.Lastpostid.Equals(feedId) &&
                                                    SBHelper.ConvertToUnixTimestamp(dt) <=
                                                    SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow))
                                                {
                                                    var ret = ShareFeed(fbAcc.AccessToken, feedId,
                                                                        facebookPage.FbUserId, "", fbAcc.FbUserId,
                                                                        facebookPage.FbUserName);
                                                    if (!string.IsNullOrEmpty(ret))
                                                    {
                                                        Thread.Sleep(1000 * 60 * shareathon.Timeintervalminutes);
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                                PageapiHitsCount = PageMaxapiHitsCount;
                                            }
                                        }

                                        fbAcc.PageShareathonUpdate        = DateTime.UtcNow;
                                        facebookPage.PageShareathonUpdate = DateTime.UtcNow;
                                        dbr.Update(fbAcc);
                                        dbr.Update(facebookPage);
                                    }
                                    else
                                    {
                                        FilterDefinition <BsonDocument> filter =
                                            new BsonDocument("strId", shareathon.strId);
                                        var update = Builders <BsonDocument> .Update.Set("FacebookStatus", 0);

                                        shareathonRepository.Update <PageShareathon>(update, filter);
                                    }
                                }
                                else
                                {
                                    PageapiHitsCount = 0;
                                }
                            }
                        }
                    }
                    catch
                    {
                        PageapiHitsCount = PageMaxapiHitsCount;
                    }
                }

                try
                {
                    if (!string.IsNullOrEmpty(shareathon.FacebookPageUrlId))
                    {
                        var urlsIds = shareathon.FacebookPageUrlId.Split(',');
                        foreach (var idUrl in urlsIds)
                        {
                            try
                            {
                                PageapiHitsCount = 0;
                                var fbAcc = dbr.Single <Facebookaccounts>(
                                    t => t.FbUserId == shareathon.Facebookaccountid);
                                var pagename = Fbpages.GetFbPageName(fbAcc.AccessToken, idUrl);
                                if (PageapiHitsCount < PageMaxapiHitsCount)
                                {
                                    var feeds = string.Empty;
                                    feeds = Fbpages.getFacebookRecentPost(fbAcc.AccessToken, idUrl);
                                    var feedId = string.Empty;
                                    if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]"))
                                    {
                                        PageapiHitsCount++;
                                        var fbpageNotes = JObject.Parse(feeds);
                                        foreach (var obj in JArray.Parse(fbpageNotes["data"].ToString()))
                                        {
                                            try
                                            {
                                                feedId = obj["id"].ToString();
                                                feedId = feedId.Split('_')[1];
                                                var dt = SBHelper.ConvertFromUnixTimestamp(
                                                    shareathon.Lastsharetimestamp);
                                                dt = dt.AddMinutes(shareathon.Timeintervalminutes);
                                                if (!shareathon.Lastpostid.Equals(feedId) &&
                                                    SBHelper.ConvertToUnixTimestamp(dt) <=
                                                    SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow))
                                                {
                                                    var ret = ShareFeed(fbAcc.AccessToken, feedId, idUrl, "",
                                                                        fbAcc.FbUserId, pagename);
                                                    if (!string.IsNullOrEmpty(ret))
                                                    {
                                                        Thread.Sleep(1000 * 60 * shareathon.Timeintervalminutes);
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                                PageapiHitsCount = PageMaxapiHitsCount;
                                            }
                                        }

                                        fbAcc.PageShareathonUpdate = DateTime.UtcNow;
                                        dbr.Update(fbAcc);
                                    }
                                    else
                                    {
                                        FilterDefinition <BsonDocument> filter =
                                            new BsonDocument("strId", shareathon.strId);
                                        var update = Builders <BsonDocument> .Update.Set("FacebookStatus", 1);

                                        shareathonRepository.Update <PageShareathon>(update, filter);
                                    }
                                }
                            }
                            catch
                            {
                                PageapiHitsCount = PageMaxapiHitsCount;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }

                GlobalVariable.pageShareathonIdsRunning.Remove(shareathon.strId);
            }
            catch (Exception e)
            {
                PageapiHitsCount = PageMaxapiHitsCount;
                Console.WriteLine(e.Message);
            }
            finally
            {
                NoOfthreadPageshreathonRunning--;
            }
        }