public string LinkedInScheduleUpdate(LinkedInManager LinkedInManager) { string json = ""; if (LinkedInManager.ScheduleTime<=DateTime.Now) { oAuthLinkedIn _oauth = new oAuthLinkedIn(); Domain.Socioboard.Domain.LinkedInAccount _LinkedinAccount = objLinkedInAccountRepository.getLinkedinAccountDetailsById(LinkedInManager.ProfileId); try { _oauth.ConsumerKey = ConfigurationManager.AppSettings["LinkedinApiKey"]; } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } try { _oauth.ConsumerSecret = ConfigurationManager.AppSettings["LinkedinSecretKey"]; } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } _oauth.Token = _LinkedinAccount.OAuthToken; string PostUrl = "https://api.linkedin.com/v1/people/~/shares?format=json"; if (string.IsNullOrEmpty(LinkedInManager.ImageUrl)) { json = _oauth.LinkedProfilePostWebRequest("POST", PostUrl, LinkedInManager.comment); } else { string imagepath = ConfigurationManager.AppSettings["DomainName"].ToString() + Regex.Split(LinkedInManager.ImageUrl, "wwwroot")[1].Replace("\\", "/"); json = _oauth.LinkedProfilePostWebRequestWithImage("POST", PostUrl, LinkedInManager.comment, imagepath); } if (!string.IsNullOrEmpty(json)) { json = "Message post on LinkedIn for Id :" + LinkedInManager.ProfileId + " and Message: " + LinkedInManager.comment; objScheduledMessageRepository.UpdateScheduledMessage(Guid.Parse(LinkedInManager.ScheduleMessageId)); } else { json= "Something Went Wrong"; } } return json; }
public string SetPostOnPage(oAuthLinkedIn oauth, string PageId, string post) { //string response1 = oauth.APIWebRequest("GET", GlobusLinkedinLib.App.Core.Global.GetCompanyUrl, null); //XmlDocument xmlCompany = new XmlDocument(); //xmlCompany.Load(new StringReader(response1)); //string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //xml += "<share><visibility><code>anyone</code></visibility><comment>"+post+"</comment></share>"; //string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><share><visibility><code>anyone</code></visibility><comment>" + post + "</comment></share>"; //string url = "https://api.linkedin.com/v1/companies/" + PageId + "/shares"; string url = "https://api.linkedin.com/v1/companies/"+PageId+"/shares?format=json"; string response = oauth.LinkedProfilePostWebRequest("POST", url, post); return response; }
public IHttpActionResult LinkedInProfileUpdate(LinkedInManager LinkedInManager) { oAuthLinkedIn _oauth = new oAuthLinkedIn(); string json = ""; Domain.Socioboard.Domain.LinkedInAccount _LinkedinAccount = objLinkedInAccountRepository.getLinkedinAccountDetailsById(LinkedInManager.ProfileId); try { _oauth.ConsumerKey = ConfigurationManager.AppSettings["LinkedinApiKey"]; } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } try { _oauth.ConsumerSecret = ConfigurationManager.AppSettings["LinkedinSecretKey"]; } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } _oauth.Token = _LinkedinAccount.OAuthToken; string PostUrl = "https://api.linkedin.com/v1/people/~/shares?format=json"; if (string.IsNullOrEmpty(LinkedInManager.ImageUrl)) { json = _oauth.LinkedProfilePostWebRequest("POST", PostUrl, LinkedInManager.comment); } else { string imagepath = ConfigurationManager.AppSettings["DomainName"].ToString() + Regex.Split(LinkedInManager.ImageUrl, "wwwroot")[1].Replace("\\", "/"); json = _oauth.LinkedProfilePostWebRequestWithImage("POST", PostUrl, LinkedInManager.comment,imagepath); } #region ScheduledMessage if (!string.IsNullOrEmpty(json)) { objScheduledMessage.Id = Guid.NewGuid(); objScheduledMessage.PicUrl = LinkedInManager.ImageUrl; objScheduledMessage.ProfileId = LinkedInManager.ProfileId; objScheduledMessage.ProfileType = "linkedin"; objScheduledMessage.ScheduleTime = DateTime.Now; objScheduledMessage.ShareMessage = LinkedInManager.comment; objScheduledMessage.Status = true; objScheduledMessage.UserId = Guid.Parse(LinkedInManager.UserId); objScheduledMessage.CreateTime = DateTime.Now; objScheduledMessage.ClientTime = DateTime.Now; if (!objScheduledMessageRepository.checkMessageExistsAtTime(objScheduledMessage.UserId, objScheduledMessage.ScheduleTime)) { objScheduledMessageRepository.addNewMessage(objScheduledMessage); } } #endregion return Ok(); }