/// <summary> /// Post linked in status /// </summary> /// <param name="message"></param> public object PostStatus(SocialMessageModel message) { var postContent = new Dictionary <string, object> { { "title", message.Title }, { "description", message.Description }, { "submitted-url", message.Url } }; if (!string.IsNullOrEmpty(message.ImageUrl)) { postContent.Add("submitted-image-url", message.ImageUrl); } var postResult = PostRequest <LinkedInShareResponse>("people/~/shares", new { comment = message.Message, content = postContent, visibility = new { code = "anyone" } }); //var key = postResult.UpdateKey; //return PostRequest<LinkedInPostResultResponse>("people/~/network/updates", new //{ // key = key //}); return(postResult); }
/// <summary> /// Post status /// </summary> /// <param name="model"></param> /// <param name="network"></param> /// <returns></returns> public ResponseModel Post(SocialMessageModel model, SocialMediaEnums.SocialNetwork network) { try { var token = GetActiveTokenOfSocialMedia(network); if (token != null) { object response = null; var authorizeModel = new SocialMediaResponseModel { AppId = token.AppId, AppSecret = token.AppSecret, AccessToken = token.AccessToken, AccessTokenSecret = token.AccessTokenSecret }; switch (network) { case SocialMediaEnums.SocialNetwork.Facebook: response = SocialUtilities.PostFacebookStatus(authorizeModel, model); break; case SocialMediaEnums.SocialNetwork.Twitter: response = SocialUtilities.PostTwitterStatus(authorizeModel, model); break; case SocialMediaEnums.SocialNetwork.LinkedIn: response = SocialUtilities.PostLinkedInStatus(authorizeModel, model); break; } var responseResult = string.Empty; if (response != null) { responseResult = SerializeUtilities.Serialize(response); } return(new ResponseModel { Success = true, Data = responseResult }); } return(new ResponseModel { Success = false, Message = T("SocialMediaToken_Message_ObjectNotFound") }); } catch (Exception exception) { return(new ResponseModel(exception)); } }
/// <summary> /// Post status /// </summary> /// <param name="messages"></param> /// <param name="page"></param> /// <returns></returns> public void Post(List <SocialMediaMessageModel> messages, Page page) { var sendingMessages = messages.Where(m => m.PostStatus && m.SocialMediaTokenId.HasValue).ToList(); if (sendingMessages.Any()) { var pageInformation = page.FriendlyUrl.ToAbsoluteUrl().DownloadPage(); var socialMessageModel = new SocialMessageModel { Title = pageInformation.Title, ImageUrl = pageInformation.ImageUrl, Url = page.FriendlyUrl.ToAbsoluteUrl(), Description = pageInformation.Description }; foreach (var message in sendingMessages) { socialMessageModel.Message = message.Message; var response = Post(socialMessageModel, message.SocialNetwork); var log = new SocialMediaLog { SocialMediaId = message.SocialMediaId, SocialMediaTokenId = message.SocialMediaTokenId.Value, PageId = page.Id, PostedContent = message.Message }; if (response.Success) { log.PostedResponse = response.Data == null ? string.Empty : response.Data.ToString(); } else { log.PostedResponse = response.DetailMessage; } _socialMediaLogService.Insert(log); } } }
/// <summary> /// Post status to Twitter /// </summary> /// <param name="model"></param> /// <param name="message"></param> public static object PostTwitterStatus(SocialMediaAuthorizeModel model, SocialMessageModel message) { var authorizer = new MvcAuthorizer { CredentialStore = new SingleUserInMemoryCredentialStore { ConsumerKey = model.AppId, ConsumerSecret = model.AppSecret, AccessToken = model.AccessToken, AccessTokenSecret = model.AccessTokenSecret } }; var context = new TwitterContext(authorizer); if (string.IsNullOrEmpty(message.ImageUrl)) { var tweet = Task.Run(() => context.TweetAsync(message.Message)); return(tweet); } //Post with image try { var webClient = new WebClient(); byte[] imageBytes = webClient.DownloadData(message.ImageUrl); var media = Task.Run(() => context.UploadMediaAsync(imageBytes, MimeMapping.GetMimeMapping(message.ImageUrl))); var tweet = Task.Run(() => context.TweetAsync(message.Message, new List <ulong> { media.Result.MediaID })); return(tweet); } catch (Exception) { var tweet = Task.Run(() => context.TweetAsync(message.Message)); return(tweet); } }
/// <summary> /// Post status to Facebook /// </summary> /// <param name="model"></param> /// <param name="message"></param> public static object PostFacebookStatus(SocialMediaAuthorizeModel model, SocialMessageModel message) { var client = new FacebookClient(model.AccessToken); if (!string.IsNullOrEmpty(message.ImageUrl)) { return(client.Post("/me/feed", new { message = message.Message, link = message.Url, picture = message.ImageUrl, name = message.Title, description = message.Description })); } return(client.Post("/me/feed", new { message = message.Message, link = message.Url, name = message.Title, description = message.Description })); }
/// <summary> /// Post status to Twitter /// </summary> /// <param name="model"></param> /// <param name="message"></param> public static object PostLinkedInStatus(SocialMediaAuthorizeModel model, SocialMessageModel message) { var linkedInHelper = new LinkedInHelper(model.AccessToken); return(linkedInHelper.PostStatus(message)); }