コード例 #1
0
        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"));
        }
コード例 #2
0
        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"));
        }
コード例 #3
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);
        }
コード例 #4
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);
        }