public IEnumerable <MongoMessageModel> UpdatePageNotifications(Facebookaccounts facebookAccount) { var notificationDetails = new List <MongoMessageModel>(); try { var notificationsDetails = FacebookApiHelper.GetPageNotifications(facebookAccount.AccessToken); var notifications = JObject.Parse(notificationsDetails); foreach (var item in notifications["data"]) { var inboxMessages = new MongoMessageModel { profileId = facebookAccount.FbUserId, type = MessageType.FacebookPageNotification, messageTimeStamp = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow) }; try { inboxMessages.Message = item.SelectToken("title")?.ToString(); inboxMessages.messageId = item.SelectToken("id").ToString(); inboxMessages.fromId = item.SelectToken("from.id").ToString(); inboxMessages.fromName = item.SelectToken("from.name").ToString(); inboxMessages.fromScreenName = item.SelectToken("from.name").ToString(); inboxMessages.fromProfileUrl = "http://graph.facebook.com/" + inboxMessages.fromId + "/picture?type=small"; inboxMessages.RecipientId = item.SelectToken("to.id").ToString(); inboxMessages.RecipientName = item.SelectToken("to.name").ToString(); inboxMessages.messageDate = Convert.ToDateTime(item["created_time"].ToString()).ToString(CultureInfo.InvariantCulture); notificationDetails.Add(inboxMessages); } catch (Exception ex) { Console.WriteLine(ex.Message); } } AddNotificationsToDb(notificationDetails); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(notificationDetails); }
private static void GetInstagramFollower(string profile_id, string access_token) { var objMessageModel = new MongoMessageModel(); var post_data = new JObject(); var next_post_data = new JObject(); var url = "https://api.instagram.com/v1/users/" + profile_id + "/followed-by?access_token=" + access_token + "&cout=500"; try { post_data = JObject.Parse(ApiInstagramHttp(url)); var items = post_data.SelectToken("data"); var link = post_data.SelectToken("pagination"); var nextpage = link.SelectToken("next_url")?.ToString(); foreach (var item in items) { try { //Guid Id = Guid.NewGuid(); var user_name = item.SelectToken("username")?.ToString(); var id = item.SelectToken("id")?.ToString(); var full_name = item.SelectToken("full_name")?.ToString(); var image_url = item.SelectToken("profile_picture")?.ToString(); var CreatedTime = DateTime.UtcNow; objMessageModel.id = ObjectId.GenerateNewId(); objMessageModel.profileId = profile_id; objMessageModel.fromId = id; objMessageModel.fromName = user_name; objMessageModel.messageId = Generatetxnid(); objMessageModel.RecipientId = profile_id; objMessageModel.RecipientName = ""; objMessageModel.fromProfileUrl = image_url; objMessageModel.type = Domain.Socioboard.Enum.MessageType.InstagramFollower; objMessageModel.FollowerCount = 0; objMessageModel.FollowingCount = 0; objMessageModel.readStatus = 1; objMessageModel.messageTimeStamp = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow); var mongorepo = new MongoRepository("MongoMessageModel"); var ret = mongorepo.Find <MongoMessageModel>(t => t.RecipientId == objMessageModel.RecipientId && t.fromId == objMessageModel.fromId && t.type == Domain.Socioboard.Enum.MessageType.InstagramFollower); var task = Task.Run(async() => { return(await ret); }); if (task.Result != null) { var count = task.Result.Count; if (count < 1) { mongorepo.Add(objMessageModel); } } } catch (Exception ex) { } } do { if (nextpage != null) { try { next_post_data = JObject.Parse(ApiInstagramHttp(nextpage)); } catch (Exception ex) { } } var items1 = next_post_data.SelectToken("data"); foreach (var item in items1) { try { //Guid Id = Guid.NewGuid(); var user_name = item.SelectToken("username")?.ToString(); var id = item.SelectToken("id")?.ToString(); var full_name = item.SelectToken("full_name")?.ToString(); var image_url = item.SelectToken("profile_picture")?.ToString(); var CreatedTime = DateTime.UtcNow; objMessageModel.id = ObjectId.GenerateNewId(); objMessageModel.profileId = profile_id; objMessageModel.fromId = id; objMessageModel.fromName = user_name; objMessageModel.messageId = Generatetxnid(); objMessageModel.RecipientId = profile_id; objMessageModel.RecipientName = ""; objMessageModel.fromProfileUrl = image_url; objMessageModel.type = Domain.Socioboard.Enum.MessageType.InstagramFollower; objMessageModel.FollowerCount = 0; objMessageModel.FollowingCount = 0; objMessageModel.readStatus = 1; objMessageModel.messageTimeStamp = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow); var mongorepo = new MongoRepository("MongoMessageModel"); var ret = mongorepo.Find <MongoMessageModel>(t => t.RecipientId == objMessageModel.RecipientId && t.fromId == objMessageModel.fromId && t.type == Domain.Socioboard.Enum.MessageType.InstagramFollower); var task = Task.Run(async() => { return(await ret); }); if (task.Result != null) { var count = task.Result.Count; if (count < 1) { mongorepo.Add(objMessageModel); } } } catch (Exception ex) { } } link = next_post_data.SelectToken("pagination"); nextpage = link.SelectToken("next_url")?.ToString(); }while (next_post_data != null); } catch (Exception ex) { } }