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")); }
public IActionResult AddFacebookPages(long userId, long groupId) { string data = Request.Form["profileaccesstoken"]; string[] accesstoken = data.Split(','); 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) { 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); } } return(Ok("Page added successfully")); }
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); }