public void PostDataPage(Shareathon item, string pageid) { Domain.Socioboard.Domain.FacebookAccount facebookpage = sharepo.getFacebookAccountDetailsByUserProfileId(pageid, item.Userid); Domain.Socioboard.Domain.FacebookAccount facebookAccount = sharepo.getFacebookAccountDetailsByUserProfileId(item.Facebookaccountid, item.Userid); if (facebookpage != null) { string feeds = FacebookHelper.getFacebookRecentPost(facebookAccount.AccessToken, facebookpage.FbUserId); string feedId = string.Empty; try { if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]")) { JObject fbpageNotes = JObject.Parse(feeds); foreach (JObject obj in JArray.Parse(fbpageNotes["data"].ToString())) { try { string feedid = obj["id"].ToString(); feedid = feedid.Split('_')[1]; if (sharepo.IsShareathonExistById(item.Id)) { string ret = FacebookHelper.ShareFeed(facebookAccount.AccessToken, feedid, facebookpage.FbUserId, "", facebookAccount.FbUserId, facebookpage.FbUserName); if (ret == "success") { Thread.Sleep(1000 * 60 * item.Timeintervalminutes); } else if (ret == "Error validating access token") { facebookAccount.IsActive = 2; facebookrepo.updateFacebookUserStatus(facebookAccount); } } } catch { } } } else { if (!feeds.Contains("The remote server returned an error: (400) Bad Request.")) { facebookpage.IsActive = 2; facebookrepo.updateFacebookUserStatus(facebookpage); } else { facebookpage.IsActive = 2; facebookrepo.updateFacebookUserStatus(facebookAccount); sharepo.UpadteShareathonByFacebookUserId(facebookAccount.FbUserId, facebookAccount.UserId); } } } catch (Exception ex) { } } }
public IHttpActionResult EditShareathon(ShareathonGroupViewModel sharethon) { string groupId = ""; string nameId = ""; ShareathonGroup eidtShareathon = sharegrprepo.getShareathon(sharethon.Id); Domain.Socioboard.Domain.FacebookAccount facebookAccount = sharepo.getFacebookAccountDetailsByUserProfileId(sharethon.Facebookaccountid, sharethon.Userid); string pageid = FacebookHelper.GetFbPageDetails(sharethon.FacebookPageUrl, facebookAccount.AccessToken); eidtShareathon.Facebookaccountid = facebookAccount.FbUserId; eidtShareathon.Facebookpageid = pageid; eidtShareathon.FacebookPageUrl = sharethon.FacebookPageUrl; eidtShareathon.Timeintervalminutes = sharethon.Timeintervalminutes; for (int i = 0; i < sharethon.FacebookGroupId.Length; i++) { string dataid = sharethon.FacebookGroupId[i]; string[] grpid = Regex.Split(dataid, "###"); groupId = grpid[0] + "," + groupId; nameId = sharethon.FacebookGroupId[i] + "," + nameId; } eidtShareathon.Facebooknameid = sharethon.Facebooknameid.TrimEnd(','); eidtShareathon.Facebookgroupid = groupId.TrimEnd(','); if (sharegrprepo.updateShareathon(eidtShareathon)) { return(Ok()); } else { return(BadRequest()); } }
public IHttpActionResult EditShareathon(ShareathonViewModel sharethon) { Shareathon eidtShareathon = sharepo.getShareathon(sharethon.Id); Domain.Socioboard.Domain.FacebookAccount facebookAccount = sharepo.getFacebookAccountDetailsByUserProfileId(sharethon.Facebookaccountid, sharethon.Userid); eidtShareathon.Facebookaccountid = facebookAccount.FbUserId; string id = ""; for (int i = 0; i < sharethon.FacebookPageId.Length; i++) { string dataid = sharethon.FacebookPageId[i]; id = dataid + "," + id; } eidtShareathon.Facebookpageid = id.TrimEnd(','); eidtShareathon.Timeintervalminutes = sharethon.Timeintervalminutes; if (sharepo.updateShareathon(eidtShareathon)) { return(Ok()); } else { return(BadRequest()); } }
public void updateFacebookUserStatus(Domain.Socioboard.Domain.FacebookAccount fbaccount) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { // Proceed action to Update Data. // And Set the reuired paremeters to find the specific values. session.CreateQuery("Update FacebookAccount set IsActive=:status where FbUserId = :fbuserid and UserId = :userid") .SetParameter("fbuserid", fbaccount.FbUserId) .SetParameter("userid", fbaccount.UserId) .SetParameter("status", fbaccount.IsActive) .ExecuteUpdate(); transaction.Commit(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); // return 0; } } //End Transaction } //End session }
/// <getUserDetails> /// Get User's all Detail from FacebookAccount by FbUserId. /// </summary> /// <param name="FbUserId">FbUserId of FacebookAccount(string)</param> /// <returns>Return a object of FacebookAccount with value of each member.</returns> public Domain.Socioboard.Domain.FacebookAccount getUserDetails(string FbUserId) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { //Proceed action to, Get User's all Detail from FacebookAccount by FbUserId. NHibernate.IQuery query = session.CreateQuery("from FacebookAccount where FbUserId = :fbuserid"); query.SetParameter("fbuserid", FbUserId); List <Domain.Socioboard.Domain.FacebookAccount> lst = new List <Domain.Socioboard.Domain.FacebookAccount>(); foreach (Domain.Socioboard.Domain.FacebookAccount item in query.Enumerable()) { lst.Add(item); break; } Domain.Socioboard.Domain.FacebookAccount fbacc = lst[0]; return(fbacc); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } } //End Transaction } //End session }
public IHttpActionResult GetShareathons(string UserId) { Guid userId = Guid.Empty; try { userId = Guid.Parse(UserId); } catch { return(BadRequest()); } if (userId == Guid.Empty) { return(BadRequest()); } else { List <Shareathon> shareatons = sharepo.getUserShareathon(userId); List <ShareathonViewModel> shareathonviewModels = new List <ShareathonViewModel>(); foreach (var item in shareatons) { ShareathonViewModel svmodel = new ShareathonViewModel(); svmodel.Id = item.Id; svmodel.IsHidden = item.IsHidden; svmodel.Lastpostid = item.Lastpostid; svmodel.Lastsharetimestamp = item.Lastsharetimestamp; svmodel.Timeintervalminutes = item.Timeintervalminutes; svmodel.Userid = item.Userid; svmodel.Facebookaccount = sharepo.getFacebookAccountDetailsByUserProfileId(item.Facebookaccountid, item.Userid); List <Domain.Socioboard.Domain.FacebookAccount> Facebookpages = new List <Domain.Socioboard.Domain.FacebookAccount>(); try { string[] fbids = item.Facebookpageid.Split(','); foreach (var id in fbids) { try { Domain.Socioboard.Domain.FacebookAccount fbaccount = sharepo.getFacebookAccountDetailsByUserProfileId(id, item.Userid); if (fbaccount != null) { Facebookpages.Add(fbaccount); } } catch { } } } catch { } svmodel.Facebookpages = Facebookpages.Where(t => t.FbUserId != "").ToList(); svmodel.pageid = item.Facebookpageid; shareathonviewModels.Add(svmodel); } return(Ok(shareathonviewModels)); } }
public IHttpActionResult ShareShareathons() { List <Shareathon> shareatons = sharepo.getShareathons(); foreach (var item in shareatons) { Domain.Socioboard.Domain.FacebookAccount facebookAccount = sharepo.getFacebookAccountDetailsByUserProfileId(item.Facebookaccountid, item.Userid); try { string[] ids = item.Facebookpageid.Split(','); foreach (string id in ids) { try { Domain.Socioboard.Domain.FacebookAccount facebookPage = sharepo.getFbAccount(Guid.Parse(id)); if (facebookPage != null) { string feeds = FacebookHelper.getFacebookRecentPost(facebookAccount.AccessToken, facebookPage.FbUserId); string feedId = string.Empty; if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]")) { JObject fbpageNotes = JObject.Parse(feeds); foreach (JObject obj in JArray.Parse(fbpageNotes["data"].ToString())) { try { feedId = obj["id"].ToString(); feedId = feedId.Split('_')[1]; } catch { } break; } if (item.Lastpostid == null || (!item.Lastpostid.Equals(feedId) && item.Lastsharetimestamp.AddMinutes(item.Timeintervalminutes) >= DateTime.UtcNow)) { FacebookHelper.ShareFeed(facebookAccount.AccessToken, feedId, facebookPage.FbUserId, "", facebookAccount.FbUserId, facebookPage.FbUserName); } } } } catch { } } } catch (Exception e) { logger.Error(e.Message); logger.Error(e.StackTrace); } } return(Ok()); }
/// <addFacebookUser> /// Add new facebok user in database. /// </summary> /// <param name="fbaccount">Set Values in a FacebookAccount Class Property and Pass the same Object of FacebookAccount Class.(Domain.FacebookAccount)</param> public void addFacebookUser(Domain.Socioboard.Domain.FacebookAccount fbaccount) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //proceed action, to save data. session.Save(fbaccount); transaction.Commit(); } //End Transaction } //End session }
public IHttpActionResult GetFacebookAcoount(string ProfileId) { try { Domain.Socioboard.Domain.FacebookAccount objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(ProfileId); return(Ok(objFacebookAccount)); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); return(BadRequest("Something Went Wrong")); } }
/// <summary> /// Get all Facebook Account of User by UserId(Guid) and FbUserId(string). /// </summary> /// <param name="Fbuserid">Fbuserid of User(String)</param> /// <param name="userId">UserId of User(Guid)</param> /// <returns>Return a object of FacebookAccount with value of each member.</returns> public Domain.Socioboard.Domain.FacebookAccount getFacebookAccountDetailsById(string Fbuserid, Guid userId) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { // proceed action, to get all Facebook Account of User by UserId(Guid) and FbUserId(string). NHibernate.IQuery query = session.CreateQuery("from FacebookAccount where FbUserId = :Fbuserid and UserId=:userId"); query.SetParameter("Fbuserid", Fbuserid); query.SetParameter("userId", userId); Domain.Socioboard.Domain.FacebookAccount result = (Domain.Socioboard.Domain.FacebookAccount)query.UniqueResult(); return(result); } //End Transaction } //End session }
public IHttpActionResult AddGroupSharethon(ShareathonGroupViewModel sharethon) { Domain.Socioboard.Domain.ShareathonGroup _ShareathonGroup = new ShareathonGroup(); string groupId = ""; string nameId = ""; Domain.Socioboard.Domain.FacebookAccount facebookAccount = sharegrprepo.getFacebookAccountDetailsByUserProfileId(sharethon.Facebookaccountid, sharethon.Userid); string pageid = FacebookHelper.GetFbPageDetails(sharethon.FacebookPageUrl, facebookAccount.AccessToken); _ShareathonGroup.Id = Guid.NewGuid(); _ShareathonGroup.Facebookpageid = pageid.TrimEnd(','); _ShareathonGroup.FacebookPageUrl = sharethon.FacebookPageUrl; _ShareathonGroup.AccessToken = facebookAccount.AccessToken; _ShareathonGroup.Facebookaccountid = facebookAccount.FbUserId; _ShareathonGroup.Userid = sharethon.Userid; _ShareathonGroup.Timeintervalminutes = sharethon.Timeintervalminutes; _ShareathonGroup.IsHidden = false; _ShareathonGroup.FacebookStatus = 1; for (int i = 0; i < sharethon.FacebookGroupId.Length; i++) { string dataid = sharethon.FacebookGroupId[i]; string[] grpid = Regex.Split(dataid, "###"); groupId = grpid[0] + "," + groupId; } _ShareathonGroup.Facebooknameid = sharethon.Facebooknameid.TrimEnd(','); _ShareathonGroup.Facebookgroupid = groupId.TrimEnd(','); if (!sharegrprepo.IsShareathonExist(sharethon.Userid, groupId, pageid)) { if (sharegrprepo.AddShareathon(_ShareathonGroup)) { return(Ok()); } else { return(BadRequest()); } } else { return(BadRequest("Shareathon exist")); } return(Ok()); }
public void PostData(ShareathonGroup item) { Domain.Socioboard.Domain.FacebookAccount facebookAccount = sharegrprepo.getFacebookAccountDetailsByUserProfileId(item.Facebookaccountid, item.Userid); string feedId = string.Empty; string[] pageid = item.Facebookpageid.Split(','); foreach (string item_str in pageid) { string feeds = FacebookHelper.getFacebookRecentPost(facebookAccount.AccessToken, item_str); try { if (!string.IsNullOrEmpty(feeds) && !feeds.Equals("[]")) { JObject fbpageNotes = JObject.Parse(feeds); foreach (JObject obj in JArray.Parse(fbpageNotes["data"].ToString())) { try { string feedid = obj["id"].ToString(); feedid = feedid.Split('_')[1]; feedId = feedid + "," + feedId; } catch { } } FacebookHelper.postfeedGroup(item.AccessToken, item.Facebookgroupid, feedId, facebookAccount.FbUserId, item.Timeintervalminutes, item.Id); } else { facebookAccount.IsActive = 2; facebookrepo.updateFacebookUserStatus(facebookAccount); sharegrprepo.UpadteShareathonByFacebookUserId(facebookAccount.FbUserId, facebookAccount.UserId); } } catch (Exception ex) { } } }
public Domain.Socioboard.Domain.FacebookAccount getFacebookAccountDetailsById(string Fbuserid) { Domain.Socioboard.Domain.FacebookAccount result = new Domain.Socioboard.Domain.FacebookAccount(); //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { // proceed action, to get all Facebook Account of User by UserId(Guid) and FbUserId(string). List <Domain.Socioboard.Domain.FacebookAccount> objlstfb = session.CreateQuery("from FacebookAccount where FbUserId = :Fbuserid") .SetParameter("Fbuserid", Fbuserid) .List <Domain.Socioboard.Domain.FacebookAccount>().ToList <Domain.Socioboard.Domain.FacebookAccount>(); if (objlstfb.Count > 0) { result = objlstfb[0]; } return(result); } //End Transaction } //End session }
public string AddFacebookPagesByUrl(string userid, string profileId, string groupId, string name) { logger.Error("AddFacebookPagesByUrllllllll"); logger.Error(userid + ", " + profileId + ", " + groupId + ", " + name); string ret = string.Empty; FacebookAccount _FacebookAccount = new FacebookAccount(); // string token = _FacebookAccount.getFbToken(); //string token = "CAAKYvwDVmnUBACyqUsvADWoAfBYTxi0kbz2gcw0sDWbBVJCXmIUG6rGez4BFSCE4hKV8eNE86eCD2iOwEWADvYuNlYupZCL4WUAGhFmRIZA6nTkdUOFeiUVHuri571QxhZA3YfSk5YkjhYy81pYtPj9FNM2mENtjCWRr5tN9zWZAKpUkw3gzsXRuEH9ZBTBwZD"; string token = ConfigurationManager.AppSettings["AccessToken1"].ToString(); try { #region fancount FacebookClient fb = new FacebookClient(); fb.AccessToken = token; int fancountPage = 0; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; //dynamic fancount = fb.Get("fql", new { q = " SELECT fan_count FROM page WHERE page_id =" + profileId }); //foreach (var friend in fancount.data) //{ // fancountPage = Convert.ToInt32(friend.fan_count); //} //dynamic friends = fb.Get("v2.0/me/friends"); //fancountPage = Convert.ToInt16(friends["summary"]["total_count"].ToString()); dynamic friends = fb.Get("v2.0/" + profileId); fancountPage = Convert.ToInt32(friends["likes"].ToString()); } catch (Exception) { fancountPage = 0; //fb.AccessToken = "CAAKYvwDVmnUBAFvCcZCQDL53q82jfR5mvgF2whNsFHgR4NmeSSUeRVpdEUpcVVgK1ERs2GZCNhJAwRHtq6MEWiRtBQnxBmZAML6dnwgpsCbjUmyT7ws6EKZBxuWbxhJqjeNCsxhac00b3L9Bf7LLlYa3PG94Uouj7vXZAZC6djZCme5BuszE3vibNFLKQqaLcgZD"; fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString(); try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; //dynamic fancount = fb.Get("fql", new { q = " SELECT fan_count FROM page WHERE page_id =" + profileId }); //foreach (var friend in fancount.data) //{ // fancountPage = Convert.ToInt32(friend.fan_count); //} //dynamic friends = fb.Get("v2.0/me/friends"); //fancountPage = Convert.ToInt16(friends["summary"]["total_count"].ToString()); dynamic friends = fb.Get("v2.0/" + profileId); fancountPage = Convert.ToInt32(friends["likes"].ToString()); } catch (Exception ex) { logger.Error("fancount : " + ex.Message); } } #endregion #region Add FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); objFacebookAccount.Id = Guid.NewGuid(); objFacebookAccount.FbUserId = profileId; objFacebookAccount.FbUserName = name; objFacebookAccount.AccessToken = ""; objFacebookAccount.Friends = Convert.ToInt32(fancountPage); objFacebookAccount.EmailId = ""; objFacebookAccount.Type = "Page"; objFacebookAccount.ProfileUrl = ""; objFacebookAccount.IsActive = 1; objFacebookAccount.UserId = Guid.Parse(userid); if (!objFacebookAccountRepository.checkFacebookUserExists(objFacebookAccount.FbUserId, objFacebookAccount.UserId)) { objFacebookAccountRepository.addFacebookUser(objFacebookAccount); } #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "facebook_page"; objSocialProfile.ProfileId = profileId; objSocialProfile.UserId = Guid.Parse(userid); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } #endregion #region Add TeamMemberProfile Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(groupId)); Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); objTeamMemberProfile.Id = Guid.NewGuid(); objTeamMemberProfile.TeamId = objTeam.Id; objTeamMemberProfile.Status = 1; objTeamMemberProfile.ProfileType = "facebook_page"; objTeamMemberProfile.StatusUpdateDate = DateTime.Now; objTeamMemberProfile.ProfileId = profileId; objTeamMemberProfile.ProfilePicUrl = "http://graph.facebook.com/" + objTeamMemberProfile.ProfileId + "/picture?type=small"; ; objTeamMemberProfile.ProfileName = name; if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeamMemberProfile.TeamId, objTeamMemberProfile.ProfileId)) { objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); } #endregion try { logger.Error(" Token:" + token); if (token != null) { FacebookClient _FacebookClient = new FacebookClient(); _FacebookClient.AccessToken = token; dynamic profile = null; try { profile = fb.Get("v2.0/" + profileId); logger.Error("AddFacebookPagesByUrl Token 1"); } catch (Exception ex) { logger.Error("fb.Get(profileId)"); logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); try { //fb.AccessToken = "CAAKYvwDVmnUBAFvCcZCQDL53q82jfR5mvgF2whNsFHgR4NmeSSUeRVpdEUpcVVgK1ERs2GZCNhJAwRHtq6MEWiRtBQnxBmZAML6dnwgpsCbjUmyT7ws6EKZBxuWbxhJqjeNCsxhac00b3L9Bf7LLlYa3PG94Uouj7vXZAZC6djZCme5BuszE3vibNFLKQqaLcgZD"; fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString(); profile = fb.Get("v2.0/" + profileId); logger.Error("AddFacebookPagesByUrl Token 2"); } catch (Exception ex2) { try { //fb.AccessToken = "CAAKYvwDVmnUBAAR2O9hxFkHzfNG8H6KbQLaiGFMRshJkbttdzhDeprklcb1yaV0rwtC7N8Xz1rsL1cykiRv2ouXtBUFxvOZCNnpFELnQGFV8jGUWjm1GYsZA40IKAORLGoAcSaa2lJkuuSoLBksB8LFPHI4cqW7VVqxgDwZCRwObxqR4Qp9QEDHxa7j1yoZD"; fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString(); profile = fb.Get("v2.0/" + profileId); logger.Error("AddFacebookPagesByUrl Token 3"); } catch (Exception ex3) { try { //fb.AccessToken = "CAAKYvwDVmnUBAFtZB8pvVrqYQonmq7MD90oNdoipDc0Te4onP2XlbZAYT4bzOZAKTr8jdhw0P1PclgLOtVxJ9g2qx4vxZAzh2CXqXAZBZAZBwkgWIVjc2B4rcXAp6O5B3gXqd8Ko5ITL9VCZCMOkMZCPc1hBsp0n8zgPt6e3Dd0vaodPBS8nMz7RD"; fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString(); profile = fb.Get("v2.0/" + profileId); logger.Error("AddFacebookPagesByUrl Token 4"); } catch (Exception ex4) { logger.Error("Finally :" + fb.AccessToken); logger.Error(ex4.Message); logger.Error(ex4.Message); } } } } try { //Edited by Sumit Gupta [10/27/2014] //AddFacebookStats(userid, _FacebookClient, profile); AddFacebookStats(userid, fb, profile); } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } //Edited by Sumit Gupta [10/29/2014] AddFbPagePost(userid, fb.AccessToken, profileId); // AddFbPagePost(userid, token, profileId); } } catch (Exception ex) { logger.Error("dynamic profile"); logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } return ret; }
public string AddFacebookGroupsInfo(string userid, string fbgroupid, string accessToken, string groupId, string email, string fbgroupname) { string ret = string.Empty; try { FacebookClient fb = new FacebookClient(); if (accessToken != null) { fb.AccessToken = accessToken; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; dynamic profile = fb.Get("v2.0/me"); #region Add FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); objFacebookAccount.Id = Guid.NewGuid(); objFacebookAccount.FbUserId = fbgroupid; objFacebookAccount.FbUserName = fbgroupname; objFacebookAccount.AccessToken = accessToken; objFacebookAccount.Friends = 0; objFacebookAccount.EmailId = email; objFacebookAccount.Type = "group"; objFacebookAccount.ProfileUrl = (Convert.ToString(profile["link"])); objFacebookAccount.IsActive = 2; objFacebookAccount.UserId = Guid.Parse(userid); if (!objFacebookAccountRepository.checkFacebookUserExists(objFacebookAccount.FbUserId, objFacebookAccount.UserId)) { objFacebookAccountRepository.addFacebookUser(objFacebookAccount); } //objFacebookAccountRepository.addFacebookUser(objFacebookAccount); #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "facebook_group"; objSocialProfile.ProfileId = fbgroupid; objSocialProfile.UserId = Guid.Parse(userid); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } #endregion #region Add TeamMemberProfile Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(groupId)); Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); objTeamMemberProfile.Id = Guid.NewGuid(); objTeamMemberProfile.TeamId = objTeam.Id; objTeamMemberProfile.Status = 1; objTeamMemberProfile.ProfileType = "facebook_group"; objTeamMemberProfile.StatusUpdateDate = DateTime.Now; objTeamMemberProfile.ProfileId = fbgroupid; if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeamMemberProfile.TeamId, objTeamMemberProfile.ProfileId)) { objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); } #endregion #region Add Facebook Feeds AddFacebookFeeds(userid, fb, profile); #endregion } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } return ret; }
public string AddFacebookPagesInfo(string userid, string profileId, string accessToken, string groupId, string email) { string ret = string.Empty; try { FacebookClient fb = new FacebookClient(); fb.AccessToken = accessToken; int fancountPage = 0; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; //dynamic fancount = fb.Get("fql", new { q = " SELECT fan_count FROM page WHERE page_id =" + profileId }); //foreach (var friend in fancount.data) //{ // fancountPage = Convert.ToInt32(friend.fan_count); //} // dynamic friends = fb.Get("v2.0/me/friends"); dynamic friends = fb.Get("v2.0/" + profileId); //fancountPage = Convert.ToInt16(friends["summary"]["total_count"].ToString()); fancountPage = Convert.ToInt32(friends["likes"].ToString()); } catch (Exception) { fancountPage = 0; } if (accessToken != null) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; dynamic profile = fb.Get("v2.0/me"); #region Add FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); objFacebookAccount.Id = Guid.NewGuid(); objFacebookAccount.FbUserId = (Convert.ToString(profile["id"])); objFacebookAccount.FbUserName = (Convert.ToString(profile["name"])); objFacebookAccount.AccessToken = accessToken; objFacebookAccount.Friends = Convert.ToInt32(fancountPage); objFacebookAccount.EmailId = email; objFacebookAccount.Type = "Page"; objFacebookAccount.ProfileUrl = (Convert.ToString(profile["link"])); objFacebookAccount.IsActive = 1; objFacebookAccount.UserId = Guid.Parse(userid); if (!objFacebookAccountRepository.checkFacebookUserExists(objFacebookAccount.FbUserId, objFacebookAccount.UserId)) { objFacebookAccountRepository.addFacebookUser(objFacebookAccount); } #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "facebook_page"; objSocialProfile.ProfileId = (Convert.ToString(profile["id"])); objSocialProfile.UserId = Guid.Parse(userid); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } #endregion #region Add TeamMemberProfile Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(groupId)); Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); objTeamMemberProfile.Id = Guid.NewGuid(); objTeamMemberProfile.TeamId = objTeam.Id; objTeamMemberProfile.Status = 1; objTeamMemberProfile.ProfileType = "facebook_page"; objTeamMemberProfile.StatusUpdateDate = DateTime.Now; objTeamMemberProfile.ProfileId = Convert.ToString(profile["id"]); objTeamMemberProfile.ProfileName = objFacebookAccount.FbUserName; objTeamMemberProfile.ProfilePicUrl = "http://graph.facebook.com/" + objTeamMemberProfile.ProfileId + "/picture?type=small"; if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeamMemberProfile.TeamId, objTeamMemberProfile.ProfileId)) { objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); } #endregion #region Add Facebook Feeds AddFacebookFeeds(userid, fb, profile); #endregion #region AddFacebook FanPge Domain.Socioboard.Domain.FacebookFanPage objFacebookFanPage = new Domain.Socioboard.Domain.FacebookFanPage(); FacebookFanPageRepository objFacebookFanPageRepository = new FacebookFanPageRepository(); objFacebookFanPage.Id = Guid.NewGuid(); objFacebookFanPage.UserId = Guid.Parse(userid); objFacebookFanPage.ProfilePageId = (Convert.ToString(profile["id"])); objFacebookFanPage.FanpageCount = fancountPage.ToString(); objFacebookFanPage.EntryDate = DateTime.UtcNow; objFacebookFanPageRepository.addFacebookUser(objFacebookFanPage); #endregion AddFbPagePost(userid, accessToken, profileId); getPageConversations(userid, fb, profile); GetFacebookPageFeed(accessToken, profileId); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } return ret; }
public string SheduleFacebookGroupMessage(string FacebookId, string UserId, string sscheduledmsgguid) { string str = string.Empty; int facint = 0; try { objScheduledMessage = objScheduledMessageRepository.GetScheduledMessageDetails(Guid.Parse(sscheduledmsgguid)); GroupScheduleMessageRepository grpschedulemessagerepo = new GroupScheduleMessageRepository(); Domain.Socioboard.Domain.GroupScheduleMessage _GroupScheduleMessage = grpschedulemessagerepo.GetScheduleMessageId(objScheduledMessage.Id); if (objFacebookAccountRepository.checkFacebookUserExists(FacebookId, Guid.Parse(UserId))) { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FacebookId, Guid.Parse(UserId)); } else { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FacebookId); } if (objFacebookAccount != null) { FacebookClient fbclient = new FacebookClient(objFacebookAccount.AccessToken); var args = new Dictionary<string, object>(); args["message"] = objScheduledMessage.ShareMessage; string imagepath = objScheduledMessage.PicUrl; var facebookpost = ""; try { if (!string.IsNullOrEmpty(imagepath)) { var media = new FacebookMediaObject { FileName = "filename", ContentType = "image/jpeg" }; byte[] img = System.IO.File.ReadAllBytes(imagepath); media.SetValue(img); args["source"] = media; facebookpost = fbclient.Post("v2.0/" + _GroupScheduleMessage.GroupId + "/photos", args).ToString(); } else { facebookpost = fbclient.Post("v2.0/" + _GroupScheduleMessage.GroupId + "/feed", args).ToString(); } } catch (Exception ex) { objFacebookAccountRepository = new FacebookAccountRepository(); objFacebookAccount.IsActive = 2; objFacebookAccountRepository.updateFacebookUserStatus(objFacebookAccount); Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); SocialProfilesRepository objSocialProfilesRepository = new SocialProfilesRepository(); string errormsg = ex.Message; if (errormsg.Contains("access token")) { objSocialProfile.UserId = objFacebookAccount.UserId; objSocialProfile.ProfileId = objFacebookAccount.FbUserId; objSocialProfile.ProfileStatus = 2; objSocialProfilesRepository.updateSocialProfileStatus(objSocialProfile); } Console.WriteLine(ex.Message); str = ex.Message; } if (!string.IsNullOrEmpty(facebookpost)) { facint++; str = "Message post on facebook for Id :" + objFacebookAccount.FbUserId + " and Message: " + objScheduledMessage.ShareMessage; ScheduledMessage schmsg = new ScheduledMessage(); schmsg.UpdateScheduledMessageByMsgId(Guid.Parse(sscheduledmsgguid)); logger.Error("SheduleFacebookGroupMessageCount" + facint); } } else { str = "facebook account not found for id" + objScheduledMessage.ProfileId; } } catch (Exception ex) { str = ex.Message; } return str; }
public string ProfilesConnected(string UserId) { try { Guid userid = Guid.Parse(UserId); SocialProfilesRepository socialRepo = new SocialProfilesRepository(); List <Domain.Socioboard.Domain.SocialProfile> lstsocioprofile = socialRepo.getAllSocialProfilesOfUser(userid); List <profileConnected> lstProfile = new List <profileConnected>(); foreach (Domain.Socioboard.Domain.SocialProfile sp in lstsocioprofile) { profileConnected pc = new profileConnected(); pc.Id = sp.Id; pc.ProfileDate = sp.ProfileDate; pc.ProfileId = sp.ProfileId; pc.ProfileStatus = sp.ProfileStatus; pc.ProfileType = sp.ProfileType; pc.UserId = sp.UserId; if (sp.ProfileType == "facebook") { try { FacebookAccountRepository objFbAccRepo = new FacebookAccountRepository(); Domain.Socioboard.Domain.FacebookAccount objFbAcc = objFbAccRepo.getUserDetails(sp.ProfileId); pc.ProfileName = objFbAcc.FbUserName; pc.ProfileImgUrl = "http://graph.facebook.com/" + sp.ProfileId + "/picture?type=small"; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "twitter") { try { TwitterAccountRepository objTwtAccRepo = new TwitterAccountRepository(); Domain.Socioboard.Domain.TwitterAccount objTwtAcc = objTwtAccRepo.getUserInfo(sp.ProfileId); pc.ProfileName = objTwtAcc.TwitterScreenName; pc.ProfileImgUrl = objTwtAcc.ProfileImageUrl; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "instagram") { try { InstagramAccountRepository objInsAccRepo = new InstagramAccountRepository(); Domain.Socioboard.Domain.InstagramAccount objInsAcc = objInsAccRepo.getInstagramAccountById(sp.ProfileId); pc.ProfileName = objInsAcc.InsUserName; pc.ProfileImgUrl = objInsAcc.ProfileUrl; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "linkedin") { try { LinkedInAccountRepository objLiAccRepo = new LinkedInAccountRepository(); Domain.Socioboard.Domain.LinkedInAccount objLiAcc = objLiAccRepo.getLinkedinAccountDetailsById(sp.ProfileId); pc.ProfileName = objLiAcc.LinkedinUserName; pc.ProfileImgUrl = objLiAcc.ProfileImageUrl; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "googleplus") { try { GooglePlusAccountRepository objGpAccRepo = new GooglePlusAccountRepository(); Domain.Socioboard.Domain.GooglePlusAccount objGpAcc = objGpAccRepo.getUserDetails(sp.ProfileId); pc.ProfileName = objGpAcc.GpUserName; pc.ProfileImgUrl = objGpAcc.GpProfileImage; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "tumblr") { try { TumblrAccountRepository objTumblrAccountRepository = new TumblrAccountRepository(); Domain.Socioboard.Domain.TumblrAccount objTumblrAccount = objTumblrAccountRepository.getTumblrAccountDetailsById(sp.ProfileId); pc.ProfileName = objTumblrAccount.tblrUserName; pc.ProfileImgUrl = objTumblrAccount.tblrProfilePicUrl; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "youtube") { try { YoutubeAccountRepository objYoutubeAccountRepository = new YoutubeAccountRepository(); Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = objYoutubeAccountRepository.getYoutubeAccountDetailsById(sp.ProfileId); pc.ProfileName = objYoutubeAccount.Ytusername; pc.ProfileImgUrl = objYoutubeAccount.Ytprofileimage; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } lstProfile.Add(pc); } return(new JavaScriptSerializer().Serialize(lstProfile)); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(new JavaScriptSerializer().Serialize("Please Try Again")); } }
public Domain.Socioboard.Domain.FacebookAccount getFacebookAccountDetailsById(string Fbuserid) { Domain.Socioboard.Domain.FacebookAccount result = new Domain.Socioboard.Domain.FacebookAccount(); //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { // proceed action, to get all Facebook Account of User by UserId(Guid) and FbUserId(string). List<Domain.Socioboard.Domain.FacebookAccount> objlstfb = session.CreateQuery("from FacebookAccount where FbUserId = :Fbuserid") .SetParameter("Fbuserid", Fbuserid) .List<Domain.Socioboard.Domain.FacebookAccount>().ToList<Domain.Socioboard.Domain.FacebookAccount>(); if (objlstfb.Count > 0) { result = objlstfb[0]; } return result; }//End Transaction }//End session }
public static List<Domain.Socioboard.Domain.FacebookAccount> GetUserTeamMemberFbProfiles() { User objUser = (User)System.Web.HttpContext.Current.Session["User"]; string groupid = System.Web.HttpContext.Current.Session["group"].ToString(); Api.FacebookAccount.FacebookAccount ApiFacebookAccount = new Api.FacebookAccount.FacebookAccount(); List<Domain.Socioboard.Domain.TeamMemberProfile> lstTeamMemberProfile = new List<Domain.Socioboard.Domain.TeamMemberProfile>(); List<Domain.Socioboard.Domain.FacebookAccount> ret_lstFacebookProfile = new List<Domain.Socioboard.Domain.FacebookAccount>(); Domain.Socioboard.Domain.FacebookAccount _FacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); Api.Team.Team objApiTeam = new Api.Team.Team(); objApiTeam.Timeout = 300000; JObject team = JObject.Parse(objApiTeam.GetTeamByGroupId(System.Web.HttpContext.Current.Session["group"].ToString())); Api.TeamMemberProfile.TeamMemberProfile objApiTeamMemberProfile = new Api.TeamMemberProfile.TeamMemberProfile(); objApiTeamMemberProfile.Timeout = 300000; lstTeamMemberProfile = (List<Domain.Socioboard.Domain.TeamMemberProfile>)new JavaScriptSerializer().Deserialize(objApiTeamMemberProfile.GetTeamMemberProfilesByTeamId(Convert.ToString(team["Id"])), typeof(List<Domain.Socioboard.Domain.TeamMemberProfile>)); foreach (Domain.Socioboard.Domain.TeamMemberProfile team_member in lstTeamMemberProfile) { _FacebookAccount = (Domain.Socioboard.Domain.FacebookAccount)new JavaScriptSerializer().Deserialize(ApiFacebookAccount.getFacebookAccountDetailsById(objUser.Id.ToString(), team_member.ProfileId), typeof(Domain.Socioboard.Domain.FacebookAccount)); if(team_member.ProfileType == "facebook_page" && !string.IsNullOrEmpty(_FacebookAccount.AccessToken)) { ret_lstFacebookProfile.Add(_FacebookAccount); } } return ret_lstFacebookProfile; }
public ActionResult UpdateProfileDetails(string Network, string ProfileName) { if (Session["User"] != null) { Domain.Socioboard.Domain.User _User = (Domain.Socioboard.Domain.User)Session["User"]; if (_User.UserType != "SuperAdmin") { return(RedirectToAction("Index", "Index")); } } else { return(RedirectToAction("Index", "Index")); } string ReturnMessage = string.Empty; bool Status = false; if (Network == "Facebook") { Domain.Socioboard.Domain.FacebookAccount objfb = (FacebookAccount)Session["UpdateProfileData"]; objfb.IsActive = 1; objfb.FbUserName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Facebook.Facebook ApiObjfb = new Api.Facebook.Facebook(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateFacebookAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } if (Network == "Twitter") { Status = true; Domain.Socioboard.Domain.TwitterAccount objfb = (TwitterAccount)Session["UpdateProfileData"]; objfb.IsActive = Status; objfb.TwitterScreenName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Twitter.Twitter ApiObjfb = new Api.Twitter.Twitter(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateTwitterAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } if (Network == "Linkedin") { Status = true; Domain.Socioboard.Domain.LinkedInAccount objfb = (LinkedInAccount)Session["UpdateProfileData"]; objfb.IsActive = Status; objfb.LinkedinUserName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Twitter.Twitter ApiObjfb = new Api.Twitter.Twitter(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateTwitterAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } if (Network == "Instagram") { Status = true; Domain.Socioboard.Domain.InstagramAccount objfb = (InstagramAccount)Session["UpdateProfileData"]; objfb.IsActive = Status; objfb.InsUserName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Instagram.Instagram ApiObjfb = new Api.Instagram.Instagram(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateInstagramAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } //if (Network == "Tumblr") //{ // Status = true; // Domain.Socioboard.Domain.TwitterAccount objfb = (TwitterAccount)Session["UpdateProfileData"]; // objfb.IsActive = Status; // objfb.TwitterScreenName = ProfileName; // string objFacebook = new JavaScriptSerializer().Serialize(objfb); // Api.Twitter.Twitter ApiObjfb = new Api.Twitter.Twitter(); // string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateTwitterAccountByAdmin(objFacebook), typeof(string))); // ReturnMessage = FbMessage; //} if (Network == "Youtube") { Status = true; Domain.Socioboard.Domain.YoutubeAccount objfb = (YoutubeAccount)Session["UpdateProfileData"]; objfb.Isactive = 1; objfb.Ytusername = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Youtube.Youtube ApiObjfb = new Api.Youtube.Youtube(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateYouTubeAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } if (Network == "GooglePlus") { Status = true; Domain.Socioboard.Domain.GooglePlusAccount objfb = (GooglePlusAccount)Session["UpdateProfileData"]; objfb.IsActive = 1; objfb.GpUserName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Twitter.Twitter ApiObjfb = new Api.Twitter.Twitter(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateTwitterAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } return(Content(ReturnMessage)); }
public string SheduleFacebookMessage(string FacebookId, string UserId, string sscheduledmsgguid) { string str = string.Empty; try { objScheduledMessage = objScheduledMessageRepository.GetScheduledMessageDetails(Guid.Parse(sscheduledmsgguid)); if (objFacebookAccountRepository.checkFacebookUserExists(FacebookId, Guid.Parse(UserId))) { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FacebookId, Guid.Parse(UserId)); } else { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FacebookId); } if (objFacebookAccount != null) { FacebookClient fbclient = new FacebookClient(objFacebookAccount.AccessToken); var args = new Dictionary<string, object>(); args["message"] = objScheduledMessage.ShareMessage; string imagepath = objScheduledMessage.PicUrl; var facebookpost = ""; try { if (!string.IsNullOrEmpty(imagepath)) { try { Uri u = new Uri(imagepath); string filename = string.Empty; string extension = string.Empty; extension = Path.GetExtension(u.AbsolutePath).Replace(".", ""); var media = new FacebookMediaObject { FileName = "filename", ContentType = "image/" + extension }; //byte[] img = System.IO.File.ReadAllBytes(imagepath); var webClient = new WebClient(); byte[] img = webClient.DownloadData(imagepath); media.SetValue(img); args["source"] = media; facebookpost = fbclient.Post("v2.0/" + objFacebookAccount.FbUserId + "/photos", args).ToString(); } catch (Exception ex) { Console.WriteLine(imagepath + "not Found"); if (!string.IsNullOrEmpty(objScheduledMessage.Url)) { args["link"] = objScheduledMessage.Url; } facebookpost = fbclient.Post("v2.0/" + objFacebookAccount.FbUserId + "/feed", args).ToString(); } } else { facebookpost = fbclient.Post("v2.0/" + objFacebookAccount.FbUserId + "/feed", args).ToString(); } } catch (Exception ex) { //FacebookAccount ObjFacebookAccount = new FacebookAccount(); //objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); objFacebookAccountRepository = new FacebookAccountRepository(); //objFacebookAccount.IsActive = 2; objFacebookAccountRepository.updateFacebookUserStatus(objFacebookAccount); Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); SocialProfilesRepository objSocialProfilesRepository = new SocialProfilesRepository(); //logger.Error(ex.Message); string errormsg = ex.Message; if (errormsg.Contains("access token")) { objSocialProfile.UserId = objFacebookAccount.UserId; objSocialProfile.ProfileId = objFacebookAccount.FbUserId; objSocialProfile.ProfileStatus = 2; objSocialProfilesRepository.updateSocialProfileStatus(objSocialProfile); } Console.WriteLine(ex.Message); str = ex.Message; } if (!string.IsNullOrEmpty(facebookpost)) { str = "Message post on facebook for Id :" + objFacebookAccount.FbUserId + " and Message: " + objScheduledMessage.ShareMessage; ScheduledMessage schmsg = new ScheduledMessage(); schmsg.UpdateScheduledMessageByMsgId(Guid.Parse(sscheduledmsgguid)); } } else { str = "facebook account not found for id" + objScheduledMessage.ProfileId; } } catch (Exception ex) { str = ex.Message; } return str; }
public string AddFacebookPagesInfo(string facebookPage, string userid, string groupId) { List<Domain.Socioboard.Domain.AddFacebookPage> lstAddFacebookPage = (List<Domain.Socioboard.Domain.AddFacebookPage>)new JavaScriptSerializer().Deserialize(facebookPage, typeof(List<Domain.Socioboard.Domain.AddFacebookPage>)); foreach (Domain.Socioboard.Domain.AddFacebookPage item in lstAddFacebookPage) { FacebookClient fb = new FacebookClient(); fb.AccessToken = item.AccessToken; dynamic profile = fb.Get("v2.0/me"); Domain.Socioboard.Domain.FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); objFacebookAccount.FbUserId = item.ProfilePageId; objFacebookAccount.FbUserName = item.Name; objFacebookAccount.AccessToken = item.AccessToken; try { objFacebookAccount.Friends = Int32.Parse(item.LikeCount); } catch (Exception ex) { objFacebookAccount.Friends = 0; } objFacebookAccount.EmailId = item.Email; objFacebookAccount.Type = "Page"; objFacebookAccount.ProfileUrl = ""; objFacebookAccount.IsActive = 1; objFacebookAccount.UserId = Guid.Parse(userid); if (!objFacebookAccountRepository.checkFacebookUserExists(objFacebookAccount.FbUserId, objFacebookAccount.UserId)) { objFacebookAccountRepository.addFacebookUser(objFacebookAccount); } #region Add TeamMemberProfile Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile(); grpProfile.Id = Guid.NewGuid(); grpProfile.GroupId = Guid.Parse(groupId); grpProfile.GroupOwnerId = objFacebookAccount.UserId; grpProfile.ProfileId = objFacebookAccount.FbUserId; grpProfile.ProfileType = "facebook_page"; grpProfile.ProfileName = objFacebookAccount.FbUserName; grpProfile.EntryDate = DateTime.UtcNow; #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "facebook_page"; objSocialProfile.ProfileId = item.ProfilePageId; objSocialProfile.UserId = Guid.Parse(userid); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); grpProfileRepo.AddGroupProfile(grpProfile); } #endregion ShareathonRepository shreathonpage = new ShareathonRepository(); ShareathonGroupRepository objShareathonGroup = new ShareathonGroupRepository(); if (shreathonpage.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId)) { shreathonpage.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId); } if (objShareathonGroup.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId)) { objShareathonGroup.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId); } new Thread(delegate() { #region Add Facebook Feeds AddFacebookFeeds(userid, fb, profile); #endregion getPageConversations(userid, fb, profile); GetFacebookPageFeed(item.AccessToken, item.ProfilePageId); }).Start(); } return "success"; }
public void getfbFriendsGenderStatsForFanPage(dynamic profile, Guid userId, ref FacebookAccount objfbacnt) { FacebookStats objfbStats = new FacebookStats(); FacebookStatsRepository objFBStatsRepo = new FacebookStatsRepository(); //int malecount = 0; //int femalecount = 0; //foreach (var item in data["data"]) //{ // if (item["gender"] == "male") // malecount++; // else if (item["gender"] == "female") // femalecount++; //} objfbStats.EntryDate = DateTime.Now; objfbStats.FbUserId = profile["id"].ToString(); //objfbStats.FemaleCount = femalecount; objfbStats.Id = Guid.NewGuid(); //objfbStats.MaleCount = malecount; objfbStats.UserId = userId; objfbStats.FanCount = objfbacnt.Friends; //objfbStats.ShareCount = getShareCount(); //objfbStats.CommentCount = getCommentCount(); //objfbStats.LikeCount = getLikeCount(); objFBStatsRepo.addFacebookStats(objfbStats); FacebookInsightStatsHelper objfbinshlpr = new FacebookInsightStatsHelper(); string pId = profile["id"].ToString(); //string pId = "329139457226886"; objfbinshlpr.getPageImpresion(pId, userId, 7); }
public string AddNewFacebookWallPosts(string FbId, string UserId) { string ret = string.Empty; long friendscount = 0; List<Domain.Socioboard.Domain.FacebookMessage> lstFacebookMessage = new List<Domain.Socioboard.Domain.FacebookMessage>(); try { Domain.Socioboard.Domain.FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); if (objFacebookAccountRepository.checkFacebookUserExists(FbId, Guid.Parse(UserId))) { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FbId, Guid.Parse(UserId)); } else { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FbId); } FacebookClient fb = new FacebookClient(); string profileId = string.Empty; string accessToken = objFacebookAccount.AccessToken; dynamic profile = null; dynamic friends = null; if (accessToken != null) { fb.AccessToken = accessToken; try { profile = fb.Get("v2.0/me"); } catch (Exception ex) { string errormssg = ex.Message; if (errormssg.Contains("changed the password")) { UpdateSocialprofileStatus(UserId, FbId); objFacebookAccount.IsActive = 2; UpdateFacebookAccount(objFacebookAccount); } logger.Error(ex.Message); logger.Error(ex.StackTrace); return "Token Expired"; } try { friends = fb.Get("v2.0/me/friends"); } catch (Exception ex) { string errormssg = ex.Message; if (errormssg.Contains("changed the password")) { UpdateSocialprofileStatus(UserId, FbId); } logger.Error(ex.Message); logger.Error(ex.StackTrace); return "Token Expired"; } try { //friendscount = Convert.ToInt16(friends["summary"]["total_count"].ToString()); } catch (Exception ex) { //try //{ // dynamic frndscount = fb.Get("fql", new { q = "SELECT friend_count FROM user WHERE uid=me()" }); // foreach (var friend in frndscount.data) // { // frndscount = friend.friend_count; // } // friendscount = Convert.ToInt16(frndscount); //} //catch (Exception exx) //{ // friendscount = 0; // logger.Error(exx.Message); // logger.Error(exx.StackTrace); //} friendscount = 0; logger.Error(ex.Message); logger.Error(ex.StackTrace); } if (objFacebookAccountRepository.checkFacebookUserExists(Convert.ToString(profile["id"]), Guid.Parse(UserId))) { //#region Add Facebook Feeds //lstNewFacebookFeeds = AddFacebookFeeds(UserId, fb, profile); //#endregion //#region Add Facebook User Home lstFacebookMessage = AddNewFacebookUserHome(UserId, fb, profile); //#endregion //#region Add Facebook User Inbox Message //AddFacebookMessageWithPagination(UserId, fb, profile); //#endregion //ret = "Facebook info Updated Successfully"; } else { //ret = "Account already Exist !"; } } return new JavaScriptSerializer().Serialize(lstFacebookMessage); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); return "Something Went Wrong"; } }
public string FacebookProfileDetails(string UserId, string ProfileId) { objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); Domain.Socioboard.Domain.FacebookAccount FacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); //objFacebookAccountRepository.getFacebookAccountDetailsById(ProfileId, Guid.Parse(UserId)); if (objFacebookAccountRepository.checkFacebookUserExists(ProfileId, Guid.Parse(UserId))) { FacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(ProfileId, Guid.Parse(UserId)); } else { FacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(ProfileId); } //long friendscount = 0; //FacebookClient fb = new FacebookClient(); //fb.AccessToken = FacebookAccount.AccessToken; //System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; //dynamic profile = fb.Get("me"); //dynamic friends = fb.Get("me/friends"); //try //{ // friendscount = Convert.ToInt16(friends["summary"]["total_count"].ToString()); //} //catch (Exception) //{ // friendscount = 0; //} //objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); //objFacebookAccount.FbUserId = (Convert.ToString(profile["id"])); //objFacebookAccount.FbUserName = (Convert.ToString(profile["name"])); //objFacebookAccount.Friends = Convert.ToInt16(friendscount); //objFacebookAccount.EmailId = (Convert.ToString(profile["email"])); //objFacebookAccount.ProfileUrl = (Convert.ToString(profile["link"])); return new JavaScriptSerializer().Serialize(FacebookAccount); }
public string AddFacebookPagesByUrl(string userid, string profileId, string groupId, string name) { logger.Error(userid + ", " + profileId + ", " + groupId + ", " + name); string ret = string.Empty; FacebookAccount _FacebookAccount = new FacebookAccount(); string token = ConfigurationManager.AppSettings["AccessToken1"].ToString(); try { #region fancount FacebookClient fb = new FacebookClient(); fb.AccessToken = token; int fancountPage = 0; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; dynamic friends = fb.Get("v2.0/" + profileId); fancountPage = Convert.ToInt32(friends["likes"].ToString()); } catch (Exception) { fancountPage = 0; fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString(); try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; dynamic friends = fb.Get("v2.0/" + profileId); fancountPage = Convert.ToInt32(friends["likes"].ToString()); } catch (Exception ex) { fancountPage = 0; fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString(); try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; dynamic friends = fb.Get("v2.0/" + profileId); fancountPage = Convert.ToInt32(friends["likes"].ToString()); } catch (Exception exx) { fancountPage = 0; fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString(); try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; dynamic friends = fb.Get("v2.0/" + profileId); fancountPage = Convert.ToInt32(friends["likes"].ToString()); } catch (Exception exxx) { logger.Error("fancount : " + exxx.Message); } } } } #endregion #region Add FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); objFacebookAccount.Id = Guid.NewGuid(); objFacebookAccount.FbUserId = profileId; objFacebookAccount.FbUserName = name; objFacebookAccount.AccessToken = ""; objFacebookAccount.Friends = Convert.ToInt32(fancountPage); objFacebookAccount.EmailId = ""; objFacebookAccount.Type = "Page"; objFacebookAccount.ProfileUrl = ""; objFacebookAccount.IsActive = 1; objFacebookAccount.UserId = Guid.Parse(userid); if (!objFacebookAccountRepository.checkFacebookUserExists(objFacebookAccount.FbUserId, objFacebookAccount.UserId)) { objFacebookAccountRepository.addFacebookUser(objFacebookAccount); } if (!string.IsNullOrEmpty(objFacebookAccount.FbUserId)) { ShareathonRepository shreathonpage = new ShareathonRepository(); ShareathonGroupRepository objShareathonGroup = new ShareathonGroupRepository(); if (shreathonpage.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId)) { shreathonpage.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId); } if (objShareathonGroup.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId)) { objShareathonGroup.UpdateShareathonByFacebookPageId(objFacebookAccount.FbUserId, objFacebookAccount.UserId); } } #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "facebook_page"; objSocialProfile.ProfileId = profileId; objSocialProfile.UserId = Guid.Parse(userid); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); #region Add TeamMemberProfile Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile(); grpProfile.Id = Guid.NewGuid(); grpProfile.GroupId = Guid.Parse(groupId); grpProfile.GroupOwnerId = objFacebookAccount.UserId; grpProfile.ProfileId = objFacebookAccount.FbUserId; grpProfile.ProfileType = "facebook_page"; grpProfile.ProfileName = name; grpProfile.EntryDate = DateTime.UtcNow; grpProfileRepo.AddGroupProfile(grpProfile); #endregion } #endregion try { logger.Error(" Token:" + token); if (token != null) { FacebookClient _FacebookClient = new FacebookClient(); _FacebookClient.AccessToken = token; dynamic profile = null; try { profile = fb.Get("v2.0/" + profileId); logger.Error("AddFacebookPagesByUrl Token 1"); } catch (Exception ex) { try { fb.AccessToken = ConfigurationManager.AppSettings["AccessToken2"].ToString(); profile = fb.Get("v2.0/" + profileId); } catch (Exception ex2) { try { //fb.AccessToken = "CAAKYvwDVmnUBAAR2O9hxFkHzfNG8H6KbQLaiGFMRshJkbttdzhDeprklcb1yaV0rwtC7N8Xz1rsL1cykiRv2ouXtBUFxvOZCNnpFELnQGFV8jGUWjm1GYsZA40IKAORLGoAcSaa2lJkuuSoLBksB8LFPHI4cqW7VVqxgDwZCRwObxqR4Qp9QEDHxa7j1yoZD"; fb.AccessToken = ConfigurationManager.AppSettings["AccessToken3"].ToString(); profile = fb.Get("v2.0/" + profileId); logger.Error("AddFacebookPagesByUrl Token 3"); } catch (Exception ex3) { try { //fb.AccessToken = "CAAKYvwDVmnUBAFtZB8pvVrqYQonmq7MD90oNdoipDc0Te4onP2XlbZAYT4bzOZAKTr8jdhw0P1PclgLOtVxJ9g2qx4vxZAzh2CXqXAZBZAZBwkgWIVjc2B4rcXAp6O5B3gXqd8Ko5ITL9VCZCMOkMZCPc1hBsp0n8zgPt6e3Dd0vaodPBS8nMz7RD"; fb.AccessToken = ConfigurationManager.AppSettings["AccessToken4"].ToString(); profile = fb.Get("v2.0/" + profileId); logger.Error("AddFacebookPagesByUrl Token 4"); } catch (Exception ex4) { logger.Error("Finally :" + fb.AccessToken); logger.Error(ex4.Message); } } } } new Thread(delegate() { AddFbPagePost(userid, fb.AccessToken, profileId); }).Start(); } } catch (Exception ex) { logger.Error(ex.StackTrace); } } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); } return ret; }
public string AddFacebookAccount(string code, string UserId, string GroupId) { string ret = string.Empty; string client_id = ConfigurationManager.AppSettings["ClientId"]; string redirect_uri = ConfigurationManager.AppSettings["RedirectUrl"]; string client_secret = ConfigurationManager.AppSettings["ClientSecretKey"]; long friendscount = 0; try { FacebookClient fb = new FacebookClient(); string profileId = string.Empty; Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("client_id", client_id); parameters.Add("redirect_uri", redirect_uri); parameters.Add("client_secret", client_secret); parameters.Add("code", code); JsonObject fbaccess_token = null; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; fbaccess_token = (JsonObject)fb.Get("/oauth/access_token", parameters); } catch (Exception ex) { try { fbaccess_token = (JsonObject)fb.Get("/oauth/access_token", parameters); } catch (Exception ex1) { return "issue_access_token"; } } string accessToken = fbaccess_token["access_token"].ToString(); if (accessToken != null) { fb.AccessToken = accessToken; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; dynamic profile = fb.Get("v2.0/me?fields=id,name,email"); dynamic friends = fb.Get("v2.0/me/friends"); try { friendscount = Convert.ToInt16(friends["summary"]["total_count"].ToString()); } catch (Exception ex) { friendscount = 0; logger.Error("friendscount >> " + ex.StackTrace); logger.Error("friendscount >> " + friends.ToString()); } if (!objFacebookAccountRepository.checkFacebookUserExists(Convert.ToString(profile["id"]), Guid.Parse(UserId))) { #region Add FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); objFacebookAccount.Id = Guid.NewGuid(); objFacebookAccount.FbUserId = (Convert.ToString(profile["id"])); objFacebookAccount.FbUserName = (Convert.ToString(profile["name"])); objFacebookAccount.AccessToken = accessToken; objFacebookAccount.Friends = Convert.ToInt16(friendscount); try { objFacebookAccount.EmailId = (Convert.ToString(profile["email"])); } catch { } objFacebookAccount.Type = "account"; try { objFacebookAccount.ProfileUrl = (Convert.ToString(profile["link"])); } catch { } objFacebookAccount.IsActive = 1; objFacebookAccount.UserId = Guid.Parse(UserId); objFacebookAccountRepository.addFacebookUser(objFacebookAccount); if (!string.IsNullOrEmpty(objFacebookAccount.FbUserId)) { ShareathonRepository shreathonpage = new ShareathonRepository(); ShareathonGroupRepository objShareathonGroup = new ShareathonGroupRepository(); if (shreathonpage.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId)) { shreathonpage.UpadteShareathonByFacebookUserId(objFacebookAccount.FbUserId, objFacebookAccount.UserId); } if (objShareathonGroup.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId)) { objShareathonGroup.UpadteShareathonByFacebookUserId(objFacebookAccount.FbUserId, objFacebookAccount.UserId); } } #endregion #region Add TeamMemberProfile Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile(); grpProfile.Id = Guid.NewGuid(); grpProfile.GroupId = Guid.Parse(GroupId); grpProfile.GroupOwnerId = Guid.Parse(UserId); grpProfile.ProfileId = objFacebookAccount.FbUserId; grpProfile.ProfileType = "facebook"; grpProfile.ProfileName = (Convert.ToString(profile["name"])); grpProfile.EntryDate = DateTime.UtcNow; grpProfile.ProfilePic = "http://graph.facebook.com/" + objFacebookAccount.FbUserId + "/picture?type=small"; #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "facebook"; objSocialProfile.ProfileId = (Convert.ToString(profile["id"])); objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; #endregion if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); grpProfileRepo.AddGroupProfile(grpProfile); } #region Add Facebook Feeds AddFacebookFeeds(UserId, fb, profile); #endregion ret = "Account Added Successfully"; ret = new JavaScriptSerializer().Serialize(objFacebookAccount); } else { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(Convert.ToString(profile["id"]), Guid.Parse(UserId)); if (objFacebookAccount.IsActive == 2) { objFacebookAccount.IsActive = 1; objFacebookAccount.AccessToken = accessToken; objFacebookAccountRepository.updateFacebookUser(objFacebookAccount); Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "facebook"; objSocialProfile.ProfileId = objFacebookAccount.FbUserId; objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; objSocialProfilesRepository.updateSocialProfileStatus(objSocialProfile); ShareathonRepository shreathonpage = new ShareathonRepository(); if (shreathonpage.IsShareathonExistFbUserId(objFacebookAccount.UserId, objFacebookAccount.FbUserId)) { shreathonpage.UpadteShareathonByFacebookUserId(objFacebookAccount.FbUserId, objFacebookAccount.UserId); } ret = "Account Updated successfully !"; } else { ret = "Account already Exist !"; } } } //return new JavaScriptSerializer().Serialize(ret); return ret; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return "Something Went Wrong"; } }
public string AddAllFbPagePost(string userid, string accesstoken, string profileid) { logger.Error("AddFbPagePost"); logger.Error(userid + ", " + accesstoken + " , " + profileid); string ret = string.Empty; Api.Socioboard.Services.FacebookAccount _FacebookAccount = new FacebookAccount(); Domain.Socioboard.Domain.FacebookAccount _facebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); try { string _nextPageDataUrl = string.Empty; FacebookClient fb = new FacebookClient(); if (string.IsNullOrEmpty(accesstoken)) { try { _facebookAccount = (Domain.Socioboard.Domain.FacebookAccount)(new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(_FacebookAccount.getFacebookAccountDetailsById(userid, profileid), typeof(Domain.Socioboard.Domain.FacebookAccount))); _facebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); Api.Socioboard.Services.FacebookAccountRepository _FacebookAccountRepository = new FacebookAccountRepository(); System.Collections.ArrayList lstFacebookAccounts = _FacebookAccountRepository.getAllFacebookAccounts(); Random _random = new Random(); var rnum = _random.Next(0, lstFacebookAccounts.Count - 1); _facebookAccount = (Domain.Socioboard.Domain.FacebookAccount)lstFacebookAccounts[rnum]; fb.AccessToken = _facebookAccount.AccessToken; } catch { }; } else fb.AccessToken = accesstoken; dynamic post = null; try { post = fb.Get("v2.0/" + profileid + "/posts"); } catch (Exception ex) { logger.Error("profileid +posts"); logger.Error(ex.Message); logger.Error(ex.StackTrace); } //dynamic post1 = fb.Get("me/posts"); _NextPageDataUrl: if (!string.IsNullOrEmpty(_nextPageDataUrl)) { fb = new FacebookClient(); post = fb.Get(_nextPageDataUrl); _nextPageDataUrl = string.Empty; } foreach (var item in post["data"]) { #region objFbPagePost.Id = Guid.NewGuid(); objFbPagePost.UserId = Guid.Parse(userid); objFbPagePost.PageId = profileid; objFbPagePost.PostId = item["id"].ToString(); objFbPagePost.PostDate = Convert.ToDateTime(item["created_time"]); objFbPagePost.EntryDate = DateTime.Now; try { objFbPagePost.Post = item["message"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.PictureUrl = item["picture"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.LinkUrl = item["link"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.IconUrl = item["icon"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.StatusType = item["status_type"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.Type = item["type"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.FromId = item["from"]["id"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.FromName = item["from"]["name"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { dynamic like = fb.Get("v2.0/" + objFbPagePost.PostId + "/likes?summary=1&limit=0"); objFbPagePost.Likes = Convert.ToInt32(like["summary"]["total_count"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { dynamic comment = fb.Get("v2.0/" + objFbPagePost.PostId + "/comments?summary=1&limit=0"); objFbPagePost.Comments = Convert.ToInt32(comment["summary"]["total_count"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { dynamic shares = fb.Get("v2.0/" + objFbPagePost.PostId); objFbPagePost.Shares = Convert.ToInt32(shares["shares"]["count"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error(ex.StackTrace); } try { if (!objFbPagePostRepository.IsPostExist(objFbPagePost)) objFbPagePostRepository.addFbPagePost(objFbPagePost); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error(ex.StackTrace); } try { AddAllFbPagePostComments(objFbPagePost.PostId, accesstoken, userid); } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } try { AddAllFbPagePostLiker(objFbPagePost.PostId, accesstoken, userid); } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } #endregion } try { _nextPageDataUrl = post["paging"]["next"]; if (!string.IsNullOrEmpty(_nextPageDataUrl)) goto _NextPageDataUrl; } catch { }; } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } return ret; }
public string GetFacebookPageData(string FbId, string UserId) { string ret = string.Empty; try { Domain.Socioboard.Domain.FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); if (objFacebookAccountRepository.checkFacebookUserExists(FbId, Guid.Parse(UserId))) { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FbId, Guid.Parse(UserId)); } else { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FbId); } FacebookClient fb = new FacebookClient(); string profileId = string.Empty; string accessToken = objFacebookAccount.AccessToken; dynamic profile = null; dynamic friends = null; if (accessToken != null) { fb.AccessToken = accessToken; int fancountPage = 0; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; friends = fb.Get("v2.0/" + FbId); fancountPage = Convert.ToInt16(friends["likes"].ToString()); objFacebookAccount.Friends = fancountPage; } catch (Exception) { fancountPage = 0; UpdateSocialprofileStatus(UserId, FbId); objFacebookAccount.IsActive = 2; UpdateFacebookAccount(objFacebookAccount); } try { profile = fb.Get("v2.0/me"); } catch (Exception ex) { string errormssg = ex.Message; logger.Error(ex.Message); logger.Error(ex.StackTrace); return "Token Expired"; } if (objFacebookAccountRepository.checkFacebookUserExists(Convert.ToString(profile["id"]), Guid.Parse(UserId))) { #region Update FacebookAccount UpdateFacebookAccount(objFacebookAccount); #endregion #region AddFacebook FanPge Domain.Socioboard.Domain.FacebookFanPage objFacebookFanPage = new Domain.Socioboard.Domain.FacebookFanPage(); FacebookFanPageRepository objFacebookFanPageRepository = new FacebookFanPageRepository(); objFacebookFanPage.Id = Guid.NewGuid(); objFacebookFanPage.UserId = Guid.Parse(UserId); objFacebookFanPage.ProfilePageId = (Convert.ToString(profile["id"])); objFacebookFanPage.FanpageCount = fancountPage.ToString(); objFacebookFanPage.EntryDate = DateTime.Now; objFacebookFanPageRepository.addFacebookUser(objFacebookFanPage); #endregion #region UpdateTeammemberprofile Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); objTeamMemberProfile.ProfileName = objFacebookAccount.FbUserName; objTeamMemberProfile.ProfilePicUrl = "http://graph.facebook.com/" + objFacebookAccount.FbUserId + "/picture?type=small"; objTeamMemberProfile.ProfileId = objFacebookAccount.FbUserId; objTeamMemberProfileRepository.updateTeamMemberbyprofileid(objTeamMemberProfile); #endregion //getUserNotifications(UserId,fb,profile); GetFacebookPageFeed(objFacebookAccount.AccessToken, objFacebookAccount.FbUserId); ret = "Facebook page info Updated Successfully"; } else { ret = "Account already Exist !"; } } return new JavaScriptSerializer().Serialize(ret); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); return "Something Went Wrong"; } }
public string GetFacebookData(string FbId, string UserId) { string ret = string.Empty; long friendscount = 0; try { Domain.Socioboard.Domain.FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); if (objFacebookAccountRepository.checkFacebookUserExists(FbId, Guid.Parse(UserId))) { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FbId, Guid.Parse(UserId)); } else { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(FbId); } FacebookClient fb = new FacebookClient(); string profileId = string.Empty; string accessToken = objFacebookAccount.AccessToken; dynamic profile = null; dynamic friends = null; if (accessToken != null) { fb.AccessToken = accessToken; try { profile = fb.Get("v2.0/me"); } catch (Exception ex) { string errormssg = ex.Message; if (errormssg.Contains("changed the password")) { UpdateSocialprofileStatus(UserId, FbId); objFacebookAccount.IsActive = 2; UpdateFacebookAccount(objFacebookAccount); } logger.Error(ex.Message); logger.Error(ex.StackTrace); return "Token Expired"; } try { friends = fb.Get("v2.0/me/friends"); } catch (Exception ex) { string errormssg = ex.Message; if (errormssg.Contains("changed the password")) { UpdateSocialprofileStatus(UserId, FbId); } logger.Error(ex.Message); logger.Error(ex.StackTrace); return "Token Expired"; } try { friendscount = Convert.ToInt16(friends["summary"]["total_count"].ToString()); objFacebookAccount.Friends = Convert.ToInt32(friendscount); } catch (Exception ex) { //try //{ // dynamic frndscount = fb.Get("fql", new { q = "SELECT friend_count FROM user WHERE uid=me()" }); // foreach (var friend in frndscount.data) // { // frndscount = friend.friend_count; // } // friendscount = Convert.ToInt16(frndscount); //} //catch (Exception exx) //{ // friendscount = 0; // logger.Error(exx.Message); // logger.Error(exx.StackTrace); //} friendscount = 0; logger.Error(ex.Message); logger.Error(ex.StackTrace); } try { objFacebookAccount.FbUserName = (Convert.ToString(profile["name"])); } catch { } if (objFacebookAccountRepository.checkFacebookUserExists(Convert.ToString(profile["id"]), Guid.Parse(UserId))) { #region Update FacebookAccount UpdateFacebookAccount(objFacebookAccount); #endregion #region UpdateTeammemberprofile Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); objTeamMemberProfile.ProfileName = objFacebookAccount.FbUserName; objTeamMemberProfile.ProfilePicUrl = "http://graph.facebook.com/" + objFacebookAccount.FbUserId + "/picture?type=small"; objTeamMemberProfile.ProfileId = objFacebookAccount.FbUserId; objTeamMemberProfileRepository.updateTeamMemberbyprofileid(objTeamMemberProfile); #endregion #region UpdateFacebook FanPge Domain.Socioboard.Domain.FacebookFanPage objFacebookFanPage = new Domain.Socioboard.Domain.FacebookFanPage(); FacebookFanPageRepository objFacebookFanPageRepository = new FacebookFanPageRepository(); objFacebookFanPage.Id = Guid.NewGuid(); objFacebookFanPage.UserId = Guid.Parse(UserId); objFacebookFanPage.ProfilePageId = FbId; objFacebookFanPage.FanpageCount = friendscount.ToString(); objFacebookFanPage.EntryDate = DateTime.Now; objFacebookFanPageRepository.addFacebookUser(objFacebookFanPage); #endregion #region Add Facebook Feeds //AddFacebookFeeds(UserId, fb, profile); AddFacebookFeedsWithPagination(UserId, fb, profile); #endregion #region Add Facebook User Home AddFacebookUserHome(UserId, fb, profile); #endregion #region Add Facebook User Inbox Message AddFacebookMessageWithPagination(UserId, fb, profile); #endregion #region Add Facebook User Notifications // getUserNotifications(UserId, fb, profile); #endregion ret = "Facebook info Updated Successfully"; } else { ret = "Account already Exist !"; } } return new JavaScriptSerializer().Serialize(ret); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); return "Something Went Wrong"; } }
public void getFacebookUserProfile(dynamic data, string accesstoken, long friends, Guid user) { SocialProfile socioprofile = new SocialProfile(); //SocialProfilesRepository socioprofilerepo = new SocialProfilesRepository(); Api.SocialProfile.SocialProfile ApiObjSocialProfile = new Api.SocialProfile.SocialProfile(); FacebookAccount fbAccount = new FacebookAccount(); //FacebookAccountRepository fbrepo = new FacebookAccountRepository(); Api.FacebookFeed.FacebookFeed ApiObjFacebookFeed = new Api.FacebookFeed.FacebookFeed(); try { try { fbAccount.AccessToken = accesstoken; } catch { } try { fbAccount.EmailId = data["email"].ToString(); } catch { } try { fbAccount.FbUserId = data["id"].ToString(); } catch { } try { fbAccount.ProfileUrl = data["link"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbAccount.FbUserName = data["name"].ToString(); } catch { } try { fbAccount.Friends = Convert.ToInt32(friends); } catch { } try { fbAccount.Id = Guid.NewGuid(); } catch { } fbAccount.IsActive = 1; try { if (HttpContext.Current.Session["fbSocial"] != null) { if (HttpContext.Current.Session["fbSocial"] == "p") { //FacebookClient fbClient = new FacebookClient(accesstoken); //int fancountPage = 0; //dynamic fancount = fbClient.Get("fql", new { q = " SELECT fan_count FROM page WHERE page_id =" + fbAccount.FbUserId }); //foreach (var friend in fancount.data) //{ // fancountPage = friend.fan_count; //} //fbAccount.Friends = Convert.ToInt32(fancountPage); fbAccount.Type = "page"; } else { fbAccount.Type = "account"; } fbAccount.UserId = user; } if (HttpContext.Current.Session["UserAndGroupsForFacebook"] != null) { try { fbAccount.UserId = user; fbAccount.Type = "account"; } catch (Exception ex) { } } } catch { } #region unused //if (HttpContext.Current.Session["login"] != null) //{ // if (HttpContext.Current.Session["login"].ToString().Equals("facebook")) // { // User usr = new User(); // UserRepository userrepo = new UserRepository(); // Registration regObject = new Registration(); // usr.AccountType = "free"; // usr.CreateDate = DateTime.Now; // usr.ExpiryDate = DateTime.Now.AddMonths(1); // usr.Id = Guid.NewGuid(); // usr.UserName = data["name"].ToString(); // usr.Password = regObject.MD5Hash(data["name"].ToString()); // usr.EmailId = data["email"].ToString(); // usr.UserStatus = 1; // if (!userrepo.IsUserExist(data["email"].ToString())) // { // UserRepository.Add(usr); // } // } //} #endregion try { socioprofile.UserId = user; } catch { } try { socioprofile.ProfileType = "facebook"; } catch { } try { socioprofile.ProfileId = data["id"].ToString(); } catch { } try { socioprofile.ProfileStatus = 1; } catch { } try { socioprofile.ProfileDate = DateTime.Now; } catch { } try { socioprofile.Id = Guid.NewGuid(); } catch { } if (HttpContext.Current.Session["fbSocial"] != null) { if (HttpContext.Current.Session["fbSocial"] == "p") { HttpContext.Current.Session["fbpagedetail"] = fbAccount; } else { if (!fbrepo.checkFacebookUserExists(fbAccount.FbUserId, user)) { fbrepo.addFacebookUser(fbAccount); if (!socioprofilerepo.checkUserProfileExist(socioprofile)) { socioprofilerepo.addNewProfileForUser(socioprofile); GroupRepository objGroupRepository = new GroupRepository(); SocioBoard.Domain.Team team = (SocioBoard.Domain.Team)HttpContext.Current.Session["GroupName"]; Groups lstDetails = objGroupRepository.getGroupName(team.GroupId); if (lstDetails.GroupName == "Socioboard") { TeamMemberProfileRepository objTeamMemberProfileRepository = new TeamMemberProfileRepository(); TeamMemberProfile teammemberprofile = new TeamMemberProfile(); teammemberprofile.Id = Guid.NewGuid(); teammemberprofile.TeamId = team.Id; teammemberprofile.ProfileId = fbAccount.FbUserId; teammemberprofile.ProfileType = "facebook"; teammemberprofile.StatusUpdateDate = DateTime.Now; objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile); } } else { socioprofilerepo.updateSocialProfile(socioprofile); } } else { HttpContext.Current.Session["alreadyexist"] = fbAccount; fbrepo.updateFacebookUser(fbAccount); if (!socioprofilerepo.checkUserProfileExist(socioprofile)) { socioprofilerepo.addNewProfileForUser(socioprofile); } else { socioprofilerepo.updateSocialProfile(socioprofile); } } } } if (HttpContext.Current.Session["UserAndGroupsForFacebook"] != null) { if (HttpContext.Current.Session["UserAndGroupsForFacebook"].ToString() == "facebook") { try { if (!fbrepo.checkFacebookUserExists(fbAccount.FbUserId, user)) { fbrepo.addFacebookUser(fbAccount); if (!socioprofilerepo.checkUserProfileExist(socioprofile)) { socioprofilerepo.addNewProfileForUser(socioprofile); } else { socioprofilerepo.updateSocialProfile(socioprofile); } } else { fbrepo.updateFacebookUser(fbAccount); if (!socioprofilerepo.checkUserProfileExist(socioprofile)) { socioprofilerepo.addNewProfileForUser(socioprofile); } else { socioprofilerepo.updateSocialProfile(socioprofile); } } if (HttpContext.Current.Session["GroupName"] != null) { GroupProfile groupprofile = new GroupProfile(); GroupProfileRepository groupprofilerepo = new GroupProfileRepository(); Groups group = (Groups)HttpContext.Current.Session["GroupName"]; groupprofile.Id = Guid.NewGuid(); groupprofile.GroupOwnerId = user; groupprofile.ProfileId = socioprofile.ProfileId; groupprofile.ProfileType = "facebook"; groupprofile.GroupId = group.Id; groupprofile.EntryDate = DateTime.Now; if (!groupprofilerepo.checkGroupProfileExists(user, group.Id, groupprofile.ProfileId)) { groupprofilerepo.AddGroupProfile(groupprofile); } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
public string AddFacebookAccount(string code, string UserId, string GroupId) { string ret = string.Empty; string client_id = ConfigurationManager.AppSettings["ClientId"]; string redirect_uri = ConfigurationManager.AppSettings["RedirectUrl"]; string client_secret = ConfigurationManager.AppSettings["ClientSecretKey"]; long friendscount = 0; try { FacebookClient fb = new FacebookClient(); string profileId = string.Empty; Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("client_id", client_id); parameters.Add("redirect_uri", redirect_uri); parameters.Add("client_secret", client_secret); parameters.Add("code", code); JsonObject fbaccess_token = null; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; fbaccess_token = (JsonObject)fb.Get("/oauth/access_token", parameters); } catch (Exception ex) { try { fbaccess_token = (JsonObject)fb.Get("/oauth/access_token", parameters); } catch (Exception ex1) { return "issue_access_token"; } } string accessToken = fbaccess_token["access_token"].ToString(); if (accessToken != null) { fb.AccessToken = accessToken; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; dynamic profile = fb.Get("v2.0/me"); dynamic friends = fb.Get("v2.0/me/friends"); try { friendscount = Convert.ToInt16(friends["summary"]["total_count"].ToString()); } catch (Exception ex) { //try //{ // dynamic frndscount = fb.Get("fql", new { q = "SELECT friend_count FROM user WHERE uid=me()" }); // foreach (var friend in frndscount.data) // { // frndscount = friend.friend_count; // } // friendscount = Convert.ToInt16(frndscount); //} //catch (Exception ex) //{ // friendscount = 0; // logger.Error(ex.Message); // logger.Error(ex.StackTrace); //} friendscount = 0; logger.Error("friendscount >> " + ex.Message); logger.Error("friendscount >> " + ex.StackTrace); logger.Error("friendscount >> " + friends.ToString()); logger.Error("friendscount >> " + friends["paging"]["next"].ToString()); } if (!objFacebookAccountRepository.checkFacebookUserExists(Convert.ToString(profile["id"]), Guid.Parse(UserId))) { #region Add FacebookAccount objFacebookAccount = new Domain.Socioboard.Domain.FacebookAccount(); objFacebookAccount.Id = Guid.NewGuid(); objFacebookAccount.FbUserId = (Convert.ToString(profile["id"])); objFacebookAccount.FbUserName = (Convert.ToString(profile["name"])); objFacebookAccount.AccessToken = accessToken; objFacebookAccount.Friends = Convert.ToInt16(friendscount); try { objFacebookAccount.EmailId = (Convert.ToString(profile["email"])); } catch (Exception ex) { } objFacebookAccount.Type = "account"; objFacebookAccount.ProfileUrl = (Convert.ToString(profile["link"])); objFacebookAccount.IsActive = 1; objFacebookAccount.UserId = Guid.Parse(UserId); objFacebookAccountRepository.addFacebookUser(objFacebookAccount); #endregion #region Add TeamMemberProfile Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId)); Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); objTeamMemberProfile.Id = Guid.NewGuid(); objTeamMemberProfile.TeamId = objTeam.Id; objTeamMemberProfile.Status = 1; objTeamMemberProfile.ProfileType = "facebook"; objTeamMemberProfile.StatusUpdateDate = DateTime.Now; objTeamMemberProfile.ProfileId = Convert.ToString(profile["id"]); objTeamMemberProfile.ProfileName = (Convert.ToString(profile["name"])); objTeamMemberProfile.ProfilePicUrl = "http://graph.facebook.com/" + objTeamMemberProfile.ProfileId + "/picture?type=small"; objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "facebook"; objSocialProfile.ProfileId = (Convert.ToString(profile["id"])); objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; #endregion if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } #region Add Facebook Feeds AddFacebookFeeds(UserId, fb, profile); #endregion #region Add Facebook User Home AddFacebookUserHome(UserId, fb, profile); #endregion #region Add Facebook User Inbox Message //AddFacebookMessage(UserId, fb, profile); AddFacebookMessageWithPagination(UserId, fb, profile); #endregion #region Add Facebook Stats AddFacebookStats(UserId, fb, profile); #endregion //getUserNotifications(UserId, fb, profile); ret = "Account Added Successfully"; ret = new JavaScriptSerializer().Serialize(objFacebookAccount); } else { objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(Convert.ToString(profile["id"]), Guid.Parse(UserId)); if (objFacebookAccount.IsActive == 2) { objFacebookAccount.IsActive = 1; objFacebookAccount.AccessToken = accessToken; objFacebookAccountRepository.updateFacebookUser(objFacebookAccount); Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "facebook"; objSocialProfile.ProfileId = objFacebookAccount.FbUserId; objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; objSocialProfilesRepository.updateSocialProfileStatus(objSocialProfile); ret = "Account Updated successfully !"; } else { ret = "Account already Exist !"; } } } //return new JavaScriptSerializer().Serialize(ret); return ret; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return "Something Went Wrong"; } }
private static async Task<ISocialSiteAccount> GetSocialAccountFromGroupProfile(Guid objUserid, Domain.Socioboard.Domain.GroupProfile objGroupProfile) { ISocialSiteAccount objSocialSiteAccount = null; string accesstoken = string.Empty; try { accesstoken = System.Web.HttpContext.Current.Session["access_token"].ToString(); } catch { } if (objGroupProfile.ProfileType == "facebook" || objGroupProfile.ProfileType == "facebook_page") { //using (Api.FacebookAccount.FacebookAccount ApiobjFacebookAccount = new Api.FacebookAccount.FacebookAccount()) //{ // ApiobjFacebookAccount.Timeout = 300000; // objSocialSiteAccount = (FacebookAccount)(new JavaScriptSerializer().Deserialize(ApiobjFacebookAccount.getFacebookAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(FacebookAccount))); //} FacebookAccount fbaccount = new FacebookAccount(); HttpResponseMessage fbresponse = await WebApiReq.GetReq("api/ApiFacebookAccount/GetFacebookAcoount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (fbresponse.IsSuccessStatusCode) { fbaccount = await fbresponse.Content.ReadAsAsync<Domain.Socioboard.Domain.FacebookAccount>(); objSocialSiteAccount = fbaccount; } } else if (objGroupProfile.ProfileType == "twitter") { //using (Api.TwitterAccount.TwitterAccount ApiobjTwitterAccount = new Api.TwitterAccount.TwitterAccount()) //{ // ApiobjTwitterAccount.Timeout = 300000; // objSocialSiteAccount = (TwitterAccount)(new JavaScriptSerializer().Deserialize(ApiobjTwitterAccount.GetTwitterAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(TwitterAccount))); //} TwitterAccount twitterAcc = new TwitterAccount(); HttpResponseMessage twitterresponse = await WebApiReq.GetReq("api/ApiTwitterAccount/GetTwitterAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (twitterresponse.IsSuccessStatusCode) { twitterAcc = await twitterresponse.Content.ReadAsAsync<Domain.Socioboard.Domain.TwitterAccount>(); objSocialSiteAccount = twitterAcc; } } else if (objGroupProfile.ProfileType == "linkedin") { //using (Api.LinkedinAccount.LinkedinAccount ApiobjLinkedinAccount = new Api.LinkedinAccount.LinkedinAccount()) //{ // ApiobjLinkedinAccount.Timeout = 300000; // objSocialSiteAccount = (LinkedInAccount)(new JavaScriptSerializer().Deserialize(ApiobjLinkedinAccount.GetLinkedinAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(LinkedInAccount))); //} LinkedInAccount LinkedinAcc = new LinkedInAccount(); HttpResponseMessage Linkedinresponse = await WebApiReq.GetReq("api/ApiLinkedinAccount/GetLinkedinAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (Linkedinresponse.IsSuccessStatusCode) { LinkedinAcc = await Linkedinresponse.Content.ReadAsAsync<Domain.Socioboard.Domain.LinkedInAccount>(); objSocialSiteAccount = LinkedinAcc; } } else if (objGroupProfile.ProfileType == "instagram") { //using (Api.InstagramAccount.InstagramAccount ApiobjInstagramAccount = new Api.InstagramAccount.InstagramAccount()) //{ // objSocialSiteAccount = (InstagramAccount)(new JavaScriptSerializer().Deserialize(ApiobjInstagramAccount.UserInformation(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(InstagramAccount))); //} InstagramAccount instAcc = new InstagramAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiInstagramAccount/GetInstagramAccount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { instAcc = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.InstagramAccount>(); objSocialSiteAccount = instAcc; } } else if (objGroupProfile.ProfileType == "youtube") { //using (Api.YoutubeAccount.YoutubeAccount ApiobjYoutubeAccount = new Api.YoutubeAccount.YoutubeAccount()) //{ // ApiobjYoutubeAccount.Timeout = 300000; // objSocialSiteAccount = (YoutubeAccount)(new JavaScriptSerializer().Deserialize(ApiobjYoutubeAccount.GetYoutubeAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(YoutubeAccount))); //} YoutubeAccount ytAcc = new YoutubeAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiYoutubeAccount/GetYoutubeAccount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { ytAcc = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.YoutubeAccount>(); objSocialSiteAccount = ytAcc; } } else if (objGroupProfile.ProfileType == "tumblr") { //using (Api.TumblrAccount.TumblrAccount ApiobjTumblrAccount = new Api.TumblrAccount.TumblrAccount()) //{ // ApiobjTumblrAccount.Timeout = 300000; // objSocialSiteAccount = (TumblrAccount)(new JavaScriptSerializer().Deserialize(ApiobjTumblrAccount.GetTumblrAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(TumblrAccount))); //} TumblrAccount ytAcc = new TumblrAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiTumblrAccount/GetTumblrAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { ytAcc = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.TumblrAccount>(); objSocialSiteAccount = ytAcc; } } else if (objGroupProfile.ProfileType == "linkedincompanypage") { //using (Api.LinkedinCompanyPage.LinkedinCompanyPage objLinkedinCompanyPage = new Api.LinkedinCompanyPage.LinkedinCompanyPage()) //{ // objLinkedinCompanyPage.Timeout = 300000; // objSocialSiteAccount = (LinkedinCompanyPage)(new JavaScriptSerializer().Deserialize(objLinkedinCompanyPage.GetLinkedinCompanyPageDetailsByUserIdAndPageId(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(LinkedinCompanyPage))); //} LinkedinCompanyPage licompanypage = new LinkedinCompanyPage(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiLinkedinCompanyPage/GetLinkedinCompanyPageDetailsByUserIdAndPageId?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { licompanypage = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.LinkedinCompanyPage>(); objSocialSiteAccount = licompanypage; } } else if (objGroupProfile.ProfileType == "gplus") { //using (Api.GooglePlusAccount.GooglePlusAccount ApiobjGooglePlusAccount = new Api.GooglePlusAccount.GooglePlusAccount()) //{ // ApiobjGooglePlusAccount.Timeout = 300000; // objSocialSiteAccount = (GooglePlusAccount)(new JavaScriptSerializer().Deserialize(ApiobjGooglePlusAccount.GetGooglePlusAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId), typeof(GooglePlusAccount))); //} GooglePlusAccount googlePlusAccount = new GooglePlusAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiGooglePlusAccount/GetGooglePlusAccount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { googlePlusAccount = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.GooglePlusAccount>(); objSocialSiteAccount = googlePlusAccount; } } else if (objGroupProfile.ProfileType == "googleanalytics") { //using (Api.GoogleAnalyticsAccount.GoogleAnalyticsAccount ApiobjGoogleAnalyticsAccount = new Api.GoogleAnalyticsAccount.GoogleAnalyticsAccount()) //{ // ApiobjGoogleAnalyticsAccount.Timeout = 300000; // objSocialSiteAccount = (GoogleAnalyticsAccount)(new JavaScriptSerializer().Deserialize(ApiobjGoogleAnalyticsAccount.GetGooglePlusAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId), typeof(GoogleAnalyticsAccount))); //} GoogleAnalyticsAccount googlePlusAccount = new GoogleAnalyticsAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiGoogleAnalyticsAccount/GetGooglePlusAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId + "&UserId=" + objUserid.ToString(), "Bearer", accesstoken); if (response.IsSuccessStatusCode) { googlePlusAccount = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.GoogleAnalyticsAccount>(); objSocialSiteAccount = googlePlusAccount; } } return objSocialSiteAccount; }