public static void GetInstagramFollower(string profile_id, string access_token, int status, Helper.AppSettings _appSettings) { Domain.Socioboard.Models.Mongo.MongoTwitterMessage _MongoTwitterMessage = new Domain.Socioboard.Models.Mongo.MongoTwitterMessage(); JObject post_data = new JObject(); string url = "https://api.instagram.com/v1/users/self/followed-by?access_token=" + access_token + "&cout=100"; bool hasData = true; while (hasData) { try { post_data = JObject.Parse(ApiInstagramHttp(url)); } catch (Exception ex) { hasData = false; } try { dynamic items = post_data["data"]; if (items == null) { hasData = false; } foreach (var item in items) { try { Guid Id = Guid.NewGuid(); string user_name = item["username"].ToString(); string id = item["id"].ToString(); string full_name = item["full_name"].ToString(); string image_url = item["profile_picture"].ToString(); DateTime CreatedTime = DateTime.UtcNow; _MongoTwitterMessage.id = ObjectId.GenerateNewId(); _MongoTwitterMessage.profileId = profile_id; _MongoTwitterMessage.messageId = id; _MongoTwitterMessage.fromId = id; _MongoTwitterMessage.fromName = user_name; _MongoTwitterMessage.RecipientId = profile_id; _MongoTwitterMessage.RecipientName = ""; _MongoTwitterMessage.fromProfileUrl = image_url; _MongoTwitterMessage.type = Domain.Socioboard.Enum.TwitterMessageType.InstagramFollower; _MongoTwitterMessage.FollowerCount = 0; _MongoTwitterMessage.FollowingCount = 0; _MongoTwitterMessage.readStatus = status; _MongoTwitterMessage.messageTimeStamp = Helper.DateExtension.ConvertToUnixTimestamp(DateTime.UtcNow); MongoRepository mongorepo = new MongoRepository("MongoTwitterMessage", _appSettings); var ret = mongorepo.Find <Domain.Socioboard.Models.Mongo.MongoTwitterMessage>(t => t.RecipientId == _MongoTwitterMessage.RecipientId && t.fromId == _MongoTwitterMessage.fromId && t.type == Domain.Socioboard.Enum.TwitterMessageType.InstagramFollower); var task = Task.Run(async() => { return(await ret); }); if (task.Result != null) { int count = task.Result.Count; if (count < 1) { mongorepo.Add(_MongoTwitterMessage); } } } catch (Exception ex) { } } url = post_data["pagination"]["next_url"].ToString(); } catch (Exception ex) { hasData = false; } } }
public static void GetInstagramFollowing(string profile_id, string access_token, int status) { Domain.Socioboard.Models.Mongo.MongoTwitterMessage _MongoTwitterMessage = new Domain.Socioboard.Models.Mongo.MongoTwitterMessage(); JObject post_data = new JObject(); string url = "https://api.instagram.com/v1/users/" + profile_id + "/follows?access_token=" + access_token + "&count=100"; try { post_data = JObject.Parse(ApiInstagramHttp(url)); } catch (Exception ex) { } try { dynamic items = post_data["data"]; foreach (var item in items) { try { Guid Id = Guid.NewGuid(); string user_name = item["username"].ToString(); string id = item["id"].ToString(); string full_name = item["full_name"].ToString(); DateTime CreatedTime = DateTime.Now; _MongoTwitterMessage.id = ObjectId.GenerateNewId(); _MongoTwitterMessage.messageId = ""; _MongoTwitterMessage.profileId = profile_id; _MongoTwitterMessage.fromId = profile_id; _MongoTwitterMessage.fromName = ""; _MongoTwitterMessage.RecipientId = id; _MongoTwitterMessage.RecipientName = full_name; _MongoTwitterMessage.twitterMsg = ""; _MongoTwitterMessage.fromProfileUrl = ""; _MongoTwitterMessage.RecipientName = ""; _MongoTwitterMessage.type = Domain.Socioboard.Enum.TwitterMessageType.InstagramFollowing; _MongoTwitterMessage.messageDate = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss"); _MongoTwitterMessage.FollowerCount = 0; _MongoTwitterMessage.FollowingCount = 0; _MongoTwitterMessage.messageTimeStamp = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow); MongoRepository mongorepo = new MongoRepository("MongoTwitterMessage"); var ret = mongorepo.Find <Domain.Socioboard.Models.Mongo.MongoTwitterMessage>(t => t.RecipientId == _MongoTwitterMessage.RecipientId && t.fromId == _MongoTwitterMessage.fromId && t.type == Domain.Socioboard.Enum.TwitterMessageType.InstagramFollowing); var task = Task.Run(async() => { return(await ret); }); if (task.Result != null) { int count = task.Result.Count; if (count < 1) { mongorepo.Add(_MongoTwitterMessage); } } } catch (Exception ex) { } } } catch (Exception ex) { } }