public string GetIntagramImages(Domain.Myfashion.Domain.InstagramAccount objInsAccount) { { InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>(); InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>(); InstagramResponse<InstagramMedia[]> userinf2 = new InstagramResponse<InstagramMedia[]>(); InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>(); MediaController objMedia = new MediaController(); CommentController objComment = new CommentController(); LikesController objLikes = new LikesController(); objInstagramComment = new Domain.Myfashion.Domain.InstagramComment(); objInstagramFeed = new Domain.Myfashion.Domain.InstagramFeed(); string html = string.Empty; int i = 0; string[] allhtmls = new string[0]; int countofimages = 0; GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users(); try { userinf2 = userInstagram.UserRecentMedia(objInsAccount.InstagramId, string.Empty, string.Empty, "20", string.Empty, string.Empty, objInsAccount.AccessToken); } catch (Exception ex) { logger.Error(ex.StackTrace); } if (userinf2 != null) { for (int j = 0; j < userinf2.data.Count(); j++) { try { usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken); bool liked = false; try { //liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken); } catch (Exception ex) { logger.Error(ex.StackTrace); } int n = usercmts.data.Count(); for (int cmt = 0; cmt < usercmts.data.Count(); cmt++) { try { objInstagramComment.Comment = Uri.EscapeDataString(usercmts.data[cmt].text); objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString(); objInstagramComment.CommentId = usercmts.data[cmt].id; objInstagramComment.EntryDate = DateTime.Now; objInstagramComment.FeedId = userinf2.data[j].id; objInstagramComment.Id = Guid.NewGuid(); objInstagramComment.InstagramId = objInsAccount.InstagramId; objInstagramComment.UserId = objInsAccount.UserId; objInstagramComment.FromName = usercmts.data[cmt].from.full_name; objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture; if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId)) objInstagramCommentRepository.addInstagramComment(objInstagramComment); } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } } objInstagramFeed.EntryDate = DateTime.Now; try { objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString(); } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objInstagramFeed.FeedId = userinf2.data[j].id; } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString(); } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objInstagramFeed.InstagramId = objInsAccount.InstagramId; } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objInstagramFeed.LikeCount = userinf2.data[j].likes.count; } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objInstagramFeed.UserId = objInsAccount.UserId; } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objInstagramFeed.CommentCount = userinf2.data[j].comments.count; } catch (Exception ex) { logger.Error(ex.StackTrace); } try { string str = userinf2.data[j].user_has_liked.ToString(); if (str == "False") { objInstagramFeed.IsLike = 0; } else { objInstagramFeed.IsLike = 1; } } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username; } catch (Exception ex) { logger.Error(ex.StackTrace); } if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId)) objInstagramFeedRepository.addInstagramFeed(objInstagramFeed); } catch (Exception ex) { logger.Error(ex.StackTrace); } i++; } } try { userinf2 = userInstagram.CurrentUserFeed(string.Empty, string.Empty, "20", objInsAccount.AccessToken); } catch (Exception ex) { logger.Error(ex.StackTrace); } if (userinf2 != null) { for (int j = 0; j < userinf2.data.Count(); j++) { try { usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken); bool liked = false; try { // liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken); } catch (Exception ex) { logger.Error(ex.StackTrace); } int n = usercmts.data.Count(); for (int cmt = 0; cmt < usercmts.data.Count(); cmt++) { try { objInstagramComment.Comment = Uri.EscapeDataString(usercmts.data[cmt].text); objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString(); objInstagramComment.CommentId = usercmts.data[cmt].id; objInstagramComment.EntryDate = DateTime.Now; objInstagramComment.FeedId = userinf2.data[j].id; objInstagramComment.Id = Guid.NewGuid(); objInstagramComment.InstagramId = objInsAccount.InstagramId; objInstagramComment.UserId = objInsAccount.UserId; objInstagramComment.FromName = usercmts.data[cmt].from.full_name; objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture; if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId)) objInstagramCommentRepository.addInstagramComment(objInstagramComment); } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } } objInstagramFeed.EntryDate = DateTime.Now; objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString(); objInstagramFeed.FeedId = userinf2.data[j].id; objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString(); objInstagramFeed.InstagramId = objInsAccount.InstagramId; objInstagramFeed.LikeCount = userinf2.data[j].likes.count; objInstagramFeed.CommentCount = userinf2.data[j].comments.count; string str = userinf2.data[j].user_has_liked.ToString(); if (str == "False") { objInstagramFeed.IsLike = 0; } else { objInstagramFeed.IsLike = 1; } objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username + "-" + userinf2.data[j].caption.from.full_name; objInstagramFeed.UserId = objInsAccount.UserId; if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId)) objInstagramFeedRepository.addInstagramFeed(objInstagramFeed); } catch (Exception ex) { logger.Error(ex.StackTrace); } i++; } } i++; string totalhtml = string.Empty; try { for (int k = 0; k < countofimages; k++) { totalhtml = totalhtml + allhtmls[k]; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } // Session["AllHtmls"] = allhtmls; return totalhtml; } }
public void getIntagramImages(object instaId) { Guid instaid = (Guid)instaId; InstagramAccountRepository objIns = new InstagramAccountRepository(); InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>(); InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>(); InstagramResponse<InstagramMedia[]> userinf2 = new InstagramResponse<InstagramMedia[]>(); InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>(); MediaController objMedia = new MediaController(); CommentController objComment = new CommentController(); LikesController objLikes = new LikesController(); InstagramFeedRepository objInsFeedRepo = new InstagramFeedRepository(); InstagramFeed objFeed = new InstagramFeed(); InstagramComment objinsComment = new InstagramComment(); InstagramCommentRepository objInsRepo = new InstagramCommentRepository(); GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"].ToString(), ConfigurationManager.AppSettings["InstagramClientSec"].ToString(), ConfigurationManager.AppSettings["InstagramCallBackURL"].ToString(), "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", ""); oAuthInstagram _api = oAuthInstagram.GetInstance(configi); ArrayList aslt = objIns.getAllInstagramAccountsOfUser(instaid); string html = string.Empty; int i = 0; // string[] allhtmls = new string[aslt.Count]; string[] allhtmls = new string[0]; int countofimages = 0; foreach (InstagramAccount item in aslt) { try { GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users(); try { userinf2 = userInstagram.UserRecentMedia(item.InstagramId, string.Empty, string.Empty, "20", string.Empty, string.Empty, item.AccessToken); } catch { } } catch { } if (userinf2 != null) { for (int j = 0; j < userinf2.data.Count(); j++) { try { usercmts = objComment.GetComment(userinf2.data[j].id, item.AccessToken); bool liked = false; try { liked = objLikes.LikeToggle(userinf2.data[j].id, item.InstagramId, item.AccessToken); } catch { } int n = usercmts.data.Count(); for (int cmt = 0; cmt < usercmts.data.Count(); cmt++) { objinsComment.Comment = usercmts.data[cmt].text; objinsComment.CommentDate = usercmts.data[cmt].created_time.ToString(); objinsComment.CommentId = usercmts.data[cmt].id; objinsComment.EntryDate = DateTime.Now.ToString(); objinsComment.FeedId = userinf2.data[j].id; objinsComment.Id = Guid.NewGuid(); objinsComment.InstagramId = item.InstagramId; objinsComment.UserId = item.UserId; objinsComment.FromName = usercmts.data[cmt].from.full_name; objinsComment.FromProfilePic = usercmts.data[cmt].from.profile_picture; if (!objInsRepo.checkInstagramCommentExists(usercmts.data[cmt].id, item.UserId)) objInsRepo.addInstagramComment(objinsComment); } objFeed.EntryDate = DateTime.Now; objFeed.FeedDate = userinf2.data[j].created_time.ToString(); objFeed.FeedId = userinf2.data[j].id; objFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString(); objFeed.InstagramId = item.InstagramId; objFeed.LikeCount = userinf2.data[j].likes.count; objFeed.UserId = item.UserId; if (!objInsFeedRepo.checkInstagramFeedExists(userinf2.data[j].id, item.UserId)) objInsFeedRepo.addInstagramFeed(objFeed); } catch { } i++; } } i++; // allhtmls[countofimages] = html; html = string.Empty; countofimages++; break; } string totalhtml = string.Empty; try { for (int k = 0; k < countofimages; k++) { totalhtml = totalhtml + allhtmls[k]; } } catch { } }
public string getIntagramImages( InstagramAccount objInsAccount) { InstagramAccountRepository objIns = new InstagramAccountRepository(); InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>(); InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>(); InstagramResponse<InstagramMedia[]> userinf2 = new InstagramResponse<InstagramMedia[]>(); InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>(); MediaController objMedia = new MediaController(); CommentController objComment = new CommentController(); LikesController objLikes = new LikesController(); InstagramFeedRepository objInsFeedRepo = new InstagramFeedRepository(); InstagramFeed objFeed = new InstagramFeed(); InstagramComment objinsComment = new InstagramComment(); InstagramCommentRepository objInsRepo = new InstagramCommentRepository(); // ArrayList aslt = objIns.getAllInstagramAccountsOfUser(instaid); string html = string.Empty; int i = 0; // string[] allhtmls = new string[aslt.Count]; string[] allhtmls = new string[0]; int countofimages = 0; GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users(); try { userinf2 = userInstagram.UserRecentMedia(objInsAccount.InstagramId,string.Empty,string.Empty,"20",string.Empty,string.Empty,objInsAccount.AccessToken); } catch(Exception ex) { logger.Error(ex.StackTrace); } if (userinf2 != null) { for (int j = 0; j < userinf2.data.Count(); j++) { try { usercmts = objComment.GetComment(userinf2.data[j].id,objInsAccount.AccessToken); bool liked = false; try { liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken); } catch(Exception ex) { logger.Error(ex.StackTrace); } int n = usercmts.data.Count(); for (int cmt = usercmts.data.Count() - 1; cmt > usercmts.data.Count() - 3; cmt--) { try { objinsComment.Comment = usercmts.data[cmt].text; objinsComment.CommentDate = usercmts.data[cmt].created_time.ToString(); objinsComment.CommentId = usercmts.data[cmt].id; objinsComment.EntryDate = DateTime.Now.ToString(); objinsComment.FeedId = userinf2.data[j].id; objinsComment.Id = Guid.NewGuid(); objinsComment.InstagramId = objInsAccount.InstagramId; objinsComment.UserId = objInsAccount.UserId; objinsComment.FromName = usercmts.data[cmt].from.full_name; objinsComment.FromProfilePic = usercmts.data[cmt].from.profile_picture; if (!objInsRepo.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId)) objInsRepo.addInstagramComment(objinsComment); } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } } objFeed.EntryDate = DateTime.Now; objFeed.FeedDate = userinf2.data[j].created_time.ToString(); objFeed.FeedId = userinf2.data[j].id; objFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString(); objFeed.InstagramId = objInsAccount.InstagramId; objFeed.LikeCount = userinf2.data[j].likes.count; objFeed.UserId = objInsAccount.UserId; if (!objInsFeedRepo.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId)) objInsFeedRepo.addInstagramFeed(objFeed); } catch(Exception ex) { logger.Error(ex.StackTrace); } i++; } } i++; string totalhtml = string.Empty; try { for (int k = 0; k < countofimages; k++) { totalhtml = totalhtml + allhtmls[k]; } } catch(Exception ex) { logger.Error(ex.StackTrace); } Session["AllHtmls"] = allhtmls; return totalhtml; }