public static List <MongoFbPostComment> FbPostComments(string postid, string AccessToken) { apiHitsCount++; List <MongoFbPostComment> lstFbPOstComment = new List <MongoFbPostComment>(); string ret = string.Empty; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; dynamic post = FbUser.getPostComments(AccessToken, postid); foreach (var item in post["data"]) { MongoFbPostComment fbPostComment = new MongoFbPostComment(); fbPostComment.Id = MongoDB.Bson.ObjectId.GenerateNewId(); fbPostComment.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); fbPostComment.PostId = postid; try { fbPostComment.CommentId = item["id"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.Comment = item["message"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.Likes = Convert.ToInt32(item["like_count"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.UserLikes = Convert.ToInt32(item["user_likes"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.Commentdate = DateTime.Parse(item["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss"); } catch (Exception ex) { fbPostComment.Commentdate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); } try { fbPostComment.FromName = item["from"]["name"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.FromId = item["from"]["id"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.PictureUrl = item["id"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { lstFbPOstComment.Add(fbPostComment); //MongoRepository fbPostRepo = new MongoRepository("MongoFbPostComment", settings); //fbPostRepo.Add<MongoFbPostComment>(fbPostComment); } catch (Exception ex) { new List <MongoFbPostComment>(); } try { // AddFbPagePostCommentsLikes(objFbPageComment.CommentId, accesstoken, userid); } catch (Exception ex) { } } } catch (Exception ex) { } return(lstFbPOstComment); }
public async Task <HttpResponseMessage> Post() { var signature = Request.Headers["X-Hub-Signature"].FirstOrDefault().Replace("sha1=", ""); var body = Request.Body.ToString(); _logger.LogInformation("post value12" + body); if (!VerifySignature(signature, body)) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } dynamic value = JsonConvert.DeserializeObject <dynamic>(body); try { if (value["object"] == "page") { var x = value["entry"][0]; _logger.LogInformation("post value1212"); if (x["changes"][0]["value"]["item"] == "status") { string profileId = Convert.ToString(x["id"]); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); string message = Convert.ToString(x["changes"][0]["value"]["message"]); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); Domain.Socioboard.Models.Mongo.MongoFacebookFeed _FacebookPagePost = new MongoFacebookFeed(); _FacebookPagePost.Id = ObjectId.GenerateNewId(); _FacebookPagePost.ProfileId = profileId; try { _FacebookPagePost.FromName = sendername; } catch { } try { _FacebookPagePost.FeedId = postid; } catch { } try { _FacebookPagePost.FeedDescription = message; } catch { _FacebookPagePost.FeedDescription = ""; } try { _FacebookPagePost.FeedDate = DateTime.Parse(postTime).ToString("yyyy/MM/dd HH:mm:ss"); } catch { _FacebookPagePost.FeedDate = DateTime.Parse(postTime).ToString("yyyy/MM/dd HH:mm:ss"); } _FacebookPagePost.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); try { MongoRepository mongorepo = new MongoRepository("MongoFacebookFeed", _appSettings); mongorepo.Add <MongoFacebookFeed>(_FacebookPagePost); } catch (Exception ex) { _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } } if (x["changes"][0]["value"]["item"] == "photo") { string profileId = Convert.ToString(x["id"]); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); string message = Convert.ToString(x["changes"][0]["value"]["message"]); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); string picture = Convert.ToString(x["changes"][0]["value"]["link"]); Domain.Socioboard.Models.Mongo.MongoFacebookFeed _FacebookPagePost = new MongoFacebookFeed(); _FacebookPagePost.Id = ObjectId.GenerateNewId(); _FacebookPagePost.ProfileId = profileId; try { _FacebookPagePost.FromName = sendername; } catch { } try { _FacebookPagePost.Picture = picture; } catch { } try { _FacebookPagePost.FeedId = postid; } catch { } try { _FacebookPagePost.FeedDescription = message; } catch { _FacebookPagePost.FeedDescription = ""; } try { _FacebookPagePost.FeedDate = DateTime.Parse(postTime).ToString("yyyy/MM/dd HH:mm:ss"); } catch { _FacebookPagePost.FeedDate = DateTime.Parse(postTime).ToString("yyyy/MM/dd HH:mm:ss"); } _FacebookPagePost.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); try { MongoRepository mongorepo = new MongoRepository("MongoFacebookFeed", _appSettings); mongorepo.Add <MongoFacebookFeed>(_FacebookPagePost); } catch (Exception ex) { _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } } if (x["changes"][0]["value"]["item"] == "comment") { string profileId = Convert.ToString(x["id"]); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); string message = Convert.ToString(x["changes"][0]["value"]["message"]); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); string comment_id = Convert.ToString(x["changes"][0]["value"]["comment_id"]); if (!string.IsNullOrEmpty(comment_id)) { MongoFbPostComment fbPostComment = new MongoFbPostComment(); fbPostComment.Id = MongoDB.Bson.ObjectId.GenerateNewId(); fbPostComment.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); fbPostComment.Commentdate = DateTime.Parse(postTime).ToString("yyyy/MM/dd HH:mm:ss"); fbPostComment.PostId = postid; fbPostComment.Likes = 0; fbPostComment.UserLikes = 0; fbPostComment.PictureUrl = message; fbPostComment.FromName = sendername; fbPostComment.FromId = sendId; fbPostComment.CommentId = comment_id; fbPostComment.Comment = message; try { MongoRepository fbPostRepo = new MongoRepository("MongoFbPostComment", _appSettings); fbPostRepo.Add <MongoFbPostComment>(fbPostComment); } catch (Exception ex) { _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } } } if (x["changes"][0]["value"]["item"] == "share") { string profileId = Convert.ToString(x["id"]); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); string message = Convert.ToString(x["changes"][0]["value"]["message"]); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); string share_id = Convert.ToString(x["changes"][0]["value"]["share_id"]); string link = Convert.ToString(x["changes"][0]["value"]["link"]); } if (x["changes"][0]["value"]["item"] == "like" || x["changes"][0]["value"]["item"] == "like") { string profileId = Convert.ToString(x["id"]); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); } } } catch (Exception ex) { } return(new HttpResponseMessage(HttpStatusCode.OK)); }
//todo : need to write codes to get all comments public static string AddFbPostComments(string postid, string AccessToken) { MongoFbPostComment fbPostComment = new MongoFbPostComment(); string ret = string.Empty; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; apiHitsCount++; //while (apiHitsCount < MaxapiHitsCount ) //{ //} dynamic post = Socioboard.Facebook.Data.FbUser.getPostComments(AccessToken, postid); foreach (var item in post["data"]) { fbPostComment.Id = MongoDB.Bson.ObjectId.GenerateNewId(); fbPostComment.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); fbPostComment.PostId = postid; try { fbPostComment.CommentId = item["id"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.Comment = item["message"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.Likes = Convert.ToInt32(item["like_count"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.UserLikes = Convert.ToInt32(item["user_likes"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.Commentdate = DateTime.Parse(item["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss"); } catch (Exception ex) { fbPostComment.Commentdate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); } try { fbPostComment.FromName = item["from"]["name"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.FromId = item["from"]["id"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbPostComment.PictureUrl = item["id"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { MongoRepository fbPostRepo = new MongoRepository("MongoFbPostComment"); var retur = fbPostRepo.Find <MongoFbPostComment>(t => t.CommentId == fbPostComment.CommentId && t.PostId == fbPostComment.PostId); var task = Task.Run(async() => { return(await retur); }); int count = task.Result.Count; if (count < 1) { fbPostRepo.Add <MongoFbPostComment>(fbPostComment); } } catch (Exception ex) { //_logger.LogInformation(ex.Message); //_logger.LogError(ex.StackTrace); } try { // AddFbPagePostCommentsLikes(objFbPageComment.CommentId, accesstoken, userid); } catch (Exception ex) { //_logger.LogInformation(ex.Message); //_logger.LogError(ex.StackTrace); } } } catch (Exception ex) { //_logger.LogInformation(ex.Message); //_logger.LogError(ex.StackTrace); } return(ret); }
public async Task <HttpResponseMessage> Post() { var signature = Request.Headers["X-Hub-Signature"].FirstOrDefault().Replace("sha1=", ""); var body = Request.Body.ToString(); string json = ""; _logger.LogInformation("post value12" + body); using (StreamReader sr = new StreamReader(this.Request.Body)) { json = sr.ReadToEnd(); } _logger.LogInformation("post value13" + json); //comment from here. //if (!VerifySignature(signature, body)) //{ // _logger.LogInformation("VerifySignature"); // return new HttpResponseMessage(HttpStatusCode.BadRequest); //} // value = JsonConvert.DeserializeObject<dynamic>(body); _logger.LogInformation("statusboady>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + json); dynamic value = JObject.Parse(json); try { _logger.LogInformation("try block start"); if (value["object"] == "page") { var x = value["entry"][0]; _logger.LogInformation("post value1212"); if (x["changes"][0]["value"]["item"] == "status") { string profileId = Convert.ToString(x["id"]); _logger.LogInformation("post profileId" + profileId); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); _logger.LogInformation("post sendId" + sendId); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); _logger.LogInformation("sendername" + sendername); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); _logger.LogInformation("postid" + postid); string message = Convert.ToString(x["changes"][0]["value"]["message"]); _logger.LogInformation("message" + message); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); _logger.LogInformation("postTime" + postTime); //string picture = Convert.ToString(x["changes"][0]["value"]["link"]); Domain.Socioboard.Models.Mongo.MongoFacebookFeed _FacebookPagePost = new MongoFacebookFeed(); _FacebookPagePost.Id = ObjectId.GenerateNewId(); _FacebookPagePost.ProfileId = profileId; _FacebookPagePost.Type = "fb_feed"; try { _FacebookPagePost.FromName = sendername; _logger.LogInformation("FromName" + sendername); } catch { _FacebookPagePost.FromName = ""; } try { _FacebookPagePost.FeedId = postid; _logger.LogInformation("FeedId" + postid); } catch { _FacebookPagePost.FeedId = ""; } try { _FacebookPagePost.FeedDescription = message; } catch { _FacebookPagePost.FeedDescription = ""; } try { _FacebookPagePost.FromId = sendId; } catch { _FacebookPagePost.FromId = ""; } try { _FacebookPagePost.Picture = ""; } catch { } try { _FacebookPagePost.shareStatus = false; } catch { } try { _FacebookPagePost.FbComment = "http://graph.facebook.com/" + postid + "/comments"; _FacebookPagePost.FbLike = "http://graph.facebook.com/" + postid + "/likes"; } catch (Exception) { _FacebookPagePost.FbComment = ""; _FacebookPagePost.FbLike = ""; } try { _FacebookPagePost.FromProfileUrl = "http://graph.facebook.com/" + profileId + "/picture?type=small"; _logger.LogInformation("FromProfileUrl" + _FacebookPagePost.FromProfileUrl); } catch (Exception) { _FacebookPagePost.FromProfileUrl = ""; } try { double datevalue = Convert.ToDouble(postTime); System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); dateTime = dateTime.AddSeconds(datevalue); string printDate = dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString(); string createddate = Convert.ToDateTime(printDate).ToString("yyyy-MM-dd h:mm tt"); DateTime convertedDate = DateTime.SpecifyKind(DateTime.Parse(createddate), DateTimeKind.Utc); _FacebookPagePost.FeedDate = convertedDate.ToString(); //_FacebookPagePost.FeedDate = DateTime.Parse(postingTime).ToString("yyyy/MM/dd HH:mm:ss"); // _FacebookPagePost.FeedDate = DateTime.Parse(x["changes"][0]["value"]["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss"); _logger.LogInformation("FeedDate" + _FacebookPagePost.FeedDate); } catch { //string postingTime = postTime.ToString(); //_FacebookPagePost.FeedDate = DateTime.Parse(postingTime).ToString("yyyy/MM/dd HH:mm:ss"); // _FacebookPagePost.FeedDate = DateTime.Parse(x["changes"][0]["value"]["created_time"]["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss"); //_FacebookPagePost.FeedDate = DateTime.Parse(postingTime).ToString(); _logger.LogError("FeedDate error" + _FacebookPagePost.FeedDate); } try { _FacebookPagePost.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); } catch { } try { MongoRepository mongorepo = new MongoRepository("MongoFacebookFeed", _appSettings); mongorepo.Add <MongoFacebookFeed>(_FacebookPagePost); _logger.LogInformation("first feeds added " + _FacebookPagePost); } catch (Exception ex) { _logger.LogInformation("Feeds 1st error"); _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } } if (x["changes"][0]["value"]["item"] == "photo") { _logger.LogInformation("photo start"); string profileId = Convert.ToString(x["id"]); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); string message = Convert.ToString(x["changes"][0]["value"]["message"]); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); _logger.LogInformation("photo post time" + postTime); string picture = Convert.ToString(x["changes"][0]["value"]["link"]); Domain.Socioboard.Models.Mongo.MongoFacebookFeed _FacebookPagePost = new MongoFacebookFeed(); _FacebookPagePost.Id = ObjectId.GenerateNewId(); _FacebookPagePost.ProfileId = profileId; try { _FacebookPagePost.FromName = sendername; } catch { } try { _FacebookPagePost.FromId = sendId; } catch { _FacebookPagePost.FromId = ""; } try { _FacebookPagePost.Picture = picture; } catch { _FacebookPagePost.Picture = ""; } try { _FacebookPagePost.FeedId = postid; } catch { } try { _FacebookPagePost.FeedDescription = message; } catch { _FacebookPagePost.FeedDescription = ""; } try { double datevalue = Convert.ToDouble(postTime); System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); dateTime = dateTime.AddSeconds(datevalue); string printDate = dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString(); string createddate = Convert.ToDateTime(printDate).ToString("yyyy-MM-dd h:mm tt"); DateTime convertedDate = DateTime.SpecifyKind(DateTime.Parse(createddate), DateTimeKind.Utc); _FacebookPagePost.FeedDate = convertedDate.ToString(); //_FacebookPagePost.FeedDate = DateTime.Parse(postTime).ToString("yyyy/MM/dd HH:mm:ss"); _logger.LogInformation("date comment " + _FacebookPagePost.FeedDate); } catch { _FacebookPagePost.FeedDate = postTime; // _FacebookPagePost.FeedDate = DateTime.Parse(postTime).ToString("yyyy/MM/dd HH:mm:ss"); _logger.LogInformation("date comment error " + _FacebookPagePost.FeedDate); } _FacebookPagePost.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); _logger.LogInformation("EntryDate " + _FacebookPagePost.EntryDate); try { MongoRepository mongorepo = new MongoRepository("MongoFacebookFeed", _appSettings); mongorepo.Add <MongoFacebookFeed>(_FacebookPagePost); _logger.LogInformation("photo Feeds data added"); } catch (Exception ex) { _logger.LogInformation("Feeds data not added Error"); _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } } if (x["changes"][0]["value"]["item"] == "comment") { string profileId = Convert.ToString(x["id"]); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); string like = Convert.ToString(x["changes"][0]["value"]["item"]); _logger.LogInformation("like" + like); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); string message = Convert.ToString(x["changes"][0]["value"]["message"]); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); _logger.LogInformation("postTime comment" + postTime); string comment_id = Convert.ToString(x["changes"][0]["value"]["comment_id"]); _logger.LogInformation("comment_id " + comment_id); if (!string.IsNullOrEmpty(comment_id)) { MongoFbPostComment fbPostComment = new MongoFbPostComment(); fbPostComment.Id = MongoDB.Bson.ObjectId.GenerateNewId(); fbPostComment.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); double datevalue = Convert.ToDouble(postTime); System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); dateTime = dateTime.AddSeconds(datevalue); string printDate = dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString(); string createddate = Convert.ToDateTime(printDate).ToString("yyyy-MM-dd h:mm tt"); DateTime convertedDate = DateTime.SpecifyKind(DateTime.Parse(createddate), DateTimeKind.Utc); fbPostComment.Commentdate = convertedDate.ToString(); _logger.LogInformation("commnet date" + fbPostComment.Commentdate); //fbPostComment.Commentdate = DateTime.Parse(postTime).ToString("yyyy/MM/dd HH:mm:ss"); fbPostComment.PostId = postid; fbPostComment.Likes = 0; fbPostComment.UserLikes = 0; fbPostComment.PictureUrl = message; fbPostComment.FromName = sendername; fbPostComment.FromId = sendId; fbPostComment.CommentId = comment_id; fbPostComment.Comment = message; try { MongoRepository fbPostRepo = new MongoRepository("MongoFbPostComment", _appSettings); fbPostRepo.Add <MongoFbPostComment>(fbPostComment); _logger.LogInformation("added data in MongoFbPostComment"); } catch (Exception ex) { _logger.LogInformation("comment error while adding in mongo"); _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } } } if (x["changes"][0]["value"]["item"] == "share") { string profileId = Convert.ToString(x["id"]); _logger.LogInformation("ProfileId" + profileId); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); _logger.LogInformation("sendId" + sendId); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); _logger.LogInformation("sendername" + sendername); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); _logger.LogInformation("postid" + postid); string message = Convert.ToString(x["changes"][0]["value"]["message"]); _logger.LogInformation("message" + message); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); _logger.LogInformation("postTime" + postTime); string share_id = Convert.ToString(x["changes"][0]["value"]["share_id"]); _logger.LogInformation("share_id" + share_id); string link = Convert.ToString(x["changes"][0]["value"]["link"]); _logger.LogInformation("link" + link); Domain.Socioboard.Models.Mongo.MongoFacebookFeed _FacebookPagePost = new MongoFacebookFeed(); _FacebookPagePost.Id = ObjectId.GenerateNewId(); _FacebookPagePost.ProfileId = profileId; _FacebookPagePost.Type = "fb_feed"; try { _FacebookPagePost.FromName = sendername; _logger.LogInformation("FromName" + sendername); } catch { _FacebookPagePost.FromName = ""; } try { _FacebookPagePost.FeedId = postid; _logger.LogInformation("FeedId" + postid); } catch { _FacebookPagePost.FeedId = ""; } try { _FacebookPagePost.FeedDescription = link; _logger.LogInformation("FeedDescription" + link); } catch (Exception ex) { _FacebookPagePost.FeedDescription = ""; _logger.LogInformation("Exception" + ex); } try { _FacebookPagePost.FromId = sendId; } catch { _FacebookPagePost.FromId = ""; } try { _FacebookPagePost.Picture = ""; } catch { } try { _FacebookPagePost.shareStatus = false; } catch { } try { _FacebookPagePost.FbComment = "http://graph.facebook.com/" + postid + "/comments"; _FacebookPagePost.FbLike = "http://graph.facebook.com/" + postid + "/likes"; } catch (Exception) { _FacebookPagePost.FbComment = ""; _FacebookPagePost.FbLike = ""; } try { _FacebookPagePost.FromProfileUrl = "http://graph.facebook.com/" + profileId + "/picture?type=small"; _logger.LogInformation("FromProfileUrl" + _FacebookPagePost.FromProfileUrl); } catch (Exception) { _FacebookPagePost.FromProfileUrl = ""; } try { double datevalue = Convert.ToDouble(postTime); System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); dateTime = dateTime.AddSeconds(datevalue); string printDate = dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString(); string createddate = Convert.ToDateTime(printDate).ToString("yyyy-MM-dd h:mm tt"); DateTime convertedDate = DateTime.SpecifyKind(DateTime.Parse(createddate), DateTimeKind.Utc); _FacebookPagePost.FeedDate = convertedDate.ToString(); //_FacebookPagePost.FeedDate = DateTime.Parse(postingTime).ToString("yyyy/MM/dd HH:mm:ss"); // _FacebookPagePost.FeedDate = DateTime.Parse(x["changes"][0]["value"]["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss"); _logger.LogInformation("FeedDate" + _FacebookPagePost.FeedDate); } catch { //string postingTime = postTime.ToString(); //_FacebookPagePost.FeedDate = DateTime.Parse(postingTime).ToString("yyyy/MM/dd HH:mm:ss"); // _FacebookPagePost.FeedDate = DateTime.Parse(x["changes"][0]["value"]["created_time"]["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss"); //_FacebookPagePost.FeedDate = DateTime.Parse(postingTime).ToString(); _logger.LogError("FeedDate error" + _FacebookPagePost.FeedDate); } try { _FacebookPagePost.EntryDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); } catch { } try { MongoRepository mongorepo = new MongoRepository("MongoFacebookFeed", _appSettings); mongorepo.Add <MongoFacebookFeed>(_FacebookPagePost); _logger.LogInformation("first feeds added" + _FacebookPagePost); } catch (Exception ex) { _logger.LogInformation("Feeds 1st error"); _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } } if (x["changes"][0]["value"]["item"] == "like" || x["changes"][0]["value"]["item"] == "like") { string profileId = Convert.ToString(x["id"]); string sendId = Convert.ToString(x["changes"][0]["value"]["sender_id"]); string sendername = Convert.ToString(x["changes"][0]["value"]["sender_name"]); string postid = Convert.ToString(x["changes"][0]["value"]["post_id"]); string postTime = Convert.ToString(x["changes"][0]["value"]["created_time"]); _logger.LogInformation("postTime in like part" + postTime); } } } catch (Exception ex) { _logger.LogInformation("Error message "); _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } return(new HttpResponseMessage(HttpStatusCode.OK)); }