public string getFacebookFeedByProfileId(string ProfileId, string FeedId)
        {
            ObjectId        fid       = ObjectId.Parse(FeedId);
            MongoRepository boardrepo = new MongoRepository("MongoFacebookFeed");

            try
            {
                var result = boardrepo.Find <MongoFacebookFeed>(x => x.Id.Equals(fid) && x.ProfileId.Equals(ProfileId)).ConfigureAwait(false);

                var task = Task.Run(async() =>
                {
                    return(await result);
                });
                IList <MongoFacebookFeed> objfbfeeds = task.Result;
                MongoFacebookFeed         fbfeeds    = objfbfeeds.FirstOrDefault();
                return(new JavaScriptSerializer().Serialize(fbfeeds));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return("Something Went Wrong");
            }

            //try
            //{
            //    Domain.Socioboard.Domain.FacebookFeed facebookfeed = objFacebookFeedRepository.getFacebookFeedByProfileId(ProfileId, FeedId);
            //    return new JavaScriptSerializer().Serialize(facebookfeed);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.StackTrace);
            //    return null;
            //}
        }
Exemple #2
0
        public int updateFacebookFeeds(Domain.Socioboard.Models.Facebookaccounts fbAcc)
        {
            apiHitsCount = 0;
            Model.DatabaseRepository dbr = new DatabaseRepository();
            if (fbAcc.LastUpdate.AddHours(1) <= DateTime.UtcNow)
            {
                if (fbAcc.IsAccessTokenActive)
                {
                    dynamic feeds   = Socioboard.Facebook.Data.FbUser.getFeeds(fbAcc.AccessToken);
                    dynamic profile = Socioboard.Facebook.Data.FbUser.getFbUser(fbAcc.AccessToken);
                    apiHitsCount++;
                    if (Convert.ToString(profile) != "Invalid Access Token")
                    {
                        fbAcc.Friends = Socioboard.Facebook.Data.FbUser.getFbFriends(fbAcc.AccessToken);
                        apiHitsCount++;
                        try
                        {
                            fbAcc.EmailId = (Convert.ToString(profile["email"]));
                        }
                        catch
                        {
                            fbAcc.EmailId = fbAcc.EmailId;
                        }
                        try
                        {
                            fbAcc.ProfileUrl = (Convert.ToString(profile["link"]));
                        }
                        catch
                        {
                            fbAcc.ProfileUrl = fbAcc.ProfileUrl;
                        }
                        try
                        {
                            fbAcc.gender = (Convert.ToString(profile["gender"]));
                        }
                        catch
                        {
                            fbAcc.gender = fbAcc.gender;
                        }
                        try
                        {
                            fbAcc.bio = (Convert.ToString(profile["bio"]));
                        }
                        catch
                        {
                            fbAcc.bio = fbAcc.bio;
                        }
                        try
                        {
                            fbAcc.about = (Convert.ToString(profile["about"]));
                        }
                        catch
                        {
                            fbAcc.about = fbAcc.about;
                        }
                        try
                        {
                            fbAcc.coverPic = (Convert.ToString(profile["cover"]["source"]));
                        }
                        catch
                        {
                            fbAcc.coverPic = fbAcc.coverPic;
                        }
                        try
                        {
                            fbAcc.birthday = (Convert.ToString(profile["birthday"]));
                        }
                        catch
                        {
                            fbAcc.birthday = fbAcc.birthday;
                        }
                        try
                        {
                            JArray arry = JArray.Parse(profile["education"]);
                            if (arry.Count > 0)
                            {
                                fbAcc.college   = Convert.ToString(arry[arry.Count - 1]["school"]["name"]);
                                fbAcc.education = Convert.ToString(arry[arry.Count - 1]["concentration"]["name"]);
                            }
                        }
                        catch
                        {
                            fbAcc.college   = fbAcc.college;
                            fbAcc.education = fbAcc.education;
                        }
                        try
                        {
                            JArray arry = JArray.Parse(profile["work"]);
                            if (arry.Count > 0)
                            {
                                fbAcc.workPosition = Convert.ToString(arry[0]["position"]["name"]);
                                fbAcc.workCompany  = Convert.ToString(arry[0]["employer"]["name"]);
                            }
                        }
                        catch
                        {
                            fbAcc.workPosition = fbAcc.workPosition;
                            fbAcc.workCompany  = fbAcc.workCompany;
                        }

                        try
                        {
                            dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(fbAcc);
                        }
                        catch { }

                        while (apiHitsCount < MaxapiHitsCount && feeds != null && feeds["data"] != null)
                        {
                            apiHitsCount++;
                            if (feeds["data"] != null)
                            {
                                Console.WriteLine(feeds["data"]);
                                foreach (var result in feeds["data"])
                                {
                                    MongoFacebookFeed objFacebookFeed = new MongoFacebookFeed();
                                    objFacebookFeed.Type      = "fb_feed";
                                    objFacebookFeed.ProfileId = fbAcc.FbUserId;
                                    objFacebookFeed.Id        = MongoDB.Bson.ObjectId.GenerateNewId();
                                    try
                                    {
                                        objFacebookFeed.FromProfileUrl = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small";
                                    }
                                    catch (Exception)
                                    {
                                        objFacebookFeed.FromProfileUrl = "http://graph.facebook.com/" + fbAcc.FbUserId + "/picture?type=small";
                                    }
                                    try
                                    {
                                        objFacebookFeed.FromName = result["from"]["name"].ToString();
                                    }
                                    catch (Exception)
                                    {
                                        objFacebookFeed.FromName = fbAcc.FbUserName;
                                    }
                                    try
                                    {
                                        objFacebookFeed.FromId = result["from"]["id"].ToString();
                                    }
                                    catch (Exception)
                                    {
                                        objFacebookFeed.FromId = fbAcc.FbUserId;
                                    }
                                    objFacebookFeed.FeedId   = result["id"].ToString();
                                    objFacebookFeed.FeedDate = DateTime.Parse(result["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss");
                                    try
                                    {
                                        objFacebookFeed.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments";
                                        objFacebookFeed.FbLike    = "http://graph.facebook.com/" + result["id"] + "/likes";
                                    }
                                    catch (Exception)
                                    {
                                    }
                                    try
                                    {
                                        objFacebookFeed.Likecount = result["likes"]["summary"]["total_count"].ToString();
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                    try
                                    {
                                        objFacebookFeed.Commentcount = result["comments"]["summary"]["total_count"].ToString();
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                    try
                                    {
                                        objFacebookFeed.postType = result["type"].ToString();
                                    }
                                    catch
                                    {
                                        objFacebookFeed.postType = "status";
                                    }
                                    try
                                    {
                                        objFacebookFeed.postingFrom = result["application"]["name"].ToString();
                                    }
                                    catch
                                    {
                                        objFacebookFeed.postingFrom = "Facebook";
                                    }
                                    try
                                    {
                                        objFacebookFeed.Picture = result["picture"].ToString();
                                    }
                                    catch (Exception ex)
                                    {
                                        objFacebookFeed.Picture = "";
                                    }

                                    string message = string.Empty;

                                    try
                                    {
                                        if (result["message"] != null)
                                        {
                                            message = result["message"];
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        try
                                        {
                                            if (result["description"] != null)
                                            {
                                                message = result["description"];
                                            }
                                        }
                                        catch (Exception exx)
                                        {
                                            try
                                            {
                                                if (result["story"] != null)
                                                {
                                                    message = result["story"];
                                                }
                                            }
                                            catch (Exception exxx)
                                            {
                                                message = string.Empty;
                                            }
                                        }
                                    }

                                    if (message == null)
                                    {
                                        message = "";
                                    }
                                    objFacebookFeed.FeedDescription  = message;
                                    objFacebookFeed.EntryDate        = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss");
                                    objFacebookFeed._facebookComment = FbPostComments(objFacebookFeed.FeedId, fbAcc.AccessToken);


                                    try
                                    {
                                        MongoRepository mongorepo = new MongoRepository("MongoFacebookFeed");
                                        var             ret       = mongorepo.Find <MongoFacebookFeed>(t => t.FeedId == objFacebookFeed.FeedId && t.ProfileId == objFacebookFeed.ProfileId);
                                        var             task      = Task.Run(async() =>
                                        {
                                            return(await ret);
                                        });
                                        int count = task.Result.Count;
                                        if (count < 1)
                                        {
                                            mongorepo.Add <MongoFacebookFeed>(objFacebookFeed);
                                        }
                                        else
                                        {
                                            try
                                            {
                                                FilterDefinition <BsonDocument> filter = new BsonDocument("FeedId", objFacebookFeed.FeedId);
                                                var update = Builders <BsonDocument> .Update.Set("postType", objFacebookFeed.postType).Set("postingFrom", objFacebookFeed.postingFrom).Set("Likecount", objFacebookFeed.Likecount).Set("Commentcount", objFacebookFeed.Commentcount);

                                                mongorepo.Update <MongoFacebookFeed>(update, filter);
                                            }
                                            catch { }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        //_logger.LogInformation(ex.Message);
                                        //_logger.LogError(ex.StackTrace);
                                    }
                                    if (apiHitsCount < MaxapiHitsCount)
                                    {
                                        //AddFbPostComments(objFacebookFeed.FeedId, fbAcc.AccessToken);
                                    }
                                }
                            }
                            else
                            {
                                apiHitsCount = MaxapiHitsCount;
                            }
                            try
                            {
                                feeds = Socioboard.Facebook.Data.FbUser.fbGet(fbAcc.AccessToken, feeds["paging"]["next"]);
                            }
                            catch
                            {
                                apiHitsCount = MaxapiHitsCount;
                            }
                        }

                        fbAcc.LastUpdate = DateTime.UtcNow;

                        dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(fbAcc);
                    }
                }
            }
            else
            {
                apiHitsCount = 0;
            }
            return(0);
        }
        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));
        }
        public static void SaveFacebookFeeds(string AccessToken, string ProfileId, string UserName)
        {
            dynamic feeds = FbUser.getFeeds(AccessToken);

            if (feeds != null)
            {
                apiHitsCount++;
                foreach (var result in feeds["data"])
                {
                    MongoFacebookFeed objFacebookFeed = new MongoFacebookFeed();
                    objFacebookFeed.Type      = "fb_feed";
                    objFacebookFeed.ProfileId = ProfileId;
                    objFacebookFeed.Id        = MongoDB.Bson.ObjectId.GenerateNewId();
                    try
                    {
                        objFacebookFeed.FromProfileUrl = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small";
                    }
                    catch (Exception)
                    {
                        objFacebookFeed.FromProfileUrl = "http://graph.facebook.com/" + ProfileId + "/picture?type=small";
                    }
                    try
                    {
                        objFacebookFeed.FromName = result["from"]["name"].ToString();
                    }
                    catch (Exception)
                    {
                        objFacebookFeed.FromName = UserName;
                    }
                    try
                    {
                        objFacebookFeed.FromId = result["from"]["id"].ToString();
                    }
                    catch (Exception)
                    {
                        objFacebookFeed.FromId = ProfileId;
                    }
                    objFacebookFeed.FeedId   = result["id"].ToString();
                    objFacebookFeed.FeedDate = DateTime.Parse(result["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss");
                    try
                    {
                        objFacebookFeed.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments";
                        objFacebookFeed.FbLike    = "http://graph.facebook.com/" + result["id"] + "/likes";
                    }
                    catch (Exception)
                    {
                    }
                    try
                    {
                        objFacebookFeed.postType = result["type"].ToString();
                    }
                    catch
                    {
                        objFacebookFeed.postType = "status";
                    }
                    try
                    {
                        objFacebookFeed.postingFrom = result["application"]["name"].ToString();
                    }
                    catch
                    {
                        objFacebookFeed.postingFrom = "Facebook";
                    }
                    try
                    {
                        objFacebookFeed.Picture = result["picture"].ToString();
                    }
                    catch (Exception ex)
                    {
                        objFacebookFeed.Picture = "";
                    }
                    try
                    {
                        objFacebookFeed.Likecount = result["likes"]["summary"]["total_count"].ToString();
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        objFacebookFeed.Commentcount = result["comments"]["summary"]["total_count"].ToString();
                    }
                    catch (Exception ex)
                    {
                    }

                    string message = string.Empty;

                    try
                    {
                        if (result["message"] != null)
                        {
                            message = result["message"];
                        }
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            if (result["description"] != null)
                            {
                                message = result["description"];
                            }
                        }
                        catch (Exception exx)
                        {
                            try
                            {
                                if (result["story"] != null)
                                {
                                    message = result["story"];
                                }
                            }
                            catch (Exception exxx)
                            {
                                message = string.Empty;
                            }
                        }
                    }

                    if (message == null)
                    {
                        message = "";
                    }
                    objFacebookFeed.FeedDescription  = message;
                    objFacebookFeed.EntryDate        = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss");
                    objFacebookFeed._facebookComment = FbPostComments(objFacebookFeed.FeedId, AccessToken);
                    try
                    {
                        MongoRepository mongorepo = new MongoRepository("MongoFacebookFeed");
                        var             ret       = mongorepo.Find <MongoFacebookFeed>(t => t.FeedId == objFacebookFeed.FeedId);
                        var             task      = Task.Run(async() =>
                        {
                            return(await ret);
                        });
                        int count = task.Result.Count;
                        if (count < 1)
                        {
                            mongorepo.Add <MongoFacebookFeed>(objFacebookFeed);
                        }
                        else
                        {
                            try
                            {
                                FilterDefinition <BsonDocument> filter = new BsonDocument("FeedId", objFacebookFeed.FeedId);
                                var update = Builders <BsonDocument> .Update.Set("postType", objFacebookFeed.postType).Set("postingFrom", objFacebookFeed.postingFrom).Set("Likecount", objFacebookFeed.Likecount).Set("Commentcount", objFacebookFeed.Commentcount).Set("_facebookComment", objFacebookFeed._facebookComment);

                                mongorepo.Update <MongoFacebookFeed>(update, filter);
                            }
                            catch { }
                        }
                    }
                    catch (Exception ex)
                    {
                        apiHitsCount = MaxapiHitsCount;
                    }
                    if (apiHitsCount < MaxapiHitsCount)
                    {
                        // AddFbPostComments(objFacebookFeed.FeedId, AccessToken);
                    }
                }
            }
            else
            {
                apiHitsCount = MaxapiHitsCount;
            }
        }
Exemple #5
0
        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));
        }