/// <addInstagramFeed> /// Add new instagram feed /// </summary> /// <param name="insfeed">Set Values in a InstagramFeed Class Property and Pass the same Object of InstagramFeed Class.(Domain.InstagramFeed)</param> public void addInstagramFeed(InstagramFeed insfeed) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Save and commit new data. session.Save(insfeed); transaction.Commit(); } //End Transaction } //End Session }
// Return the instagram feed of this user // Not very felxible because of api account limitations public InstagramFeed GetFeed() { _client = CheckClient(_client, _baseUrl); var request = new RestRequest("/v1/users/self/media/recent/?access_token=" + _accessToken, Method.GET); request.AddHeader("cache-control", "no-cache"); request.AddHeader("Connection", "keep-alive"); request.AddHeader("Accept-Encoding", "gzip, deflate"); request.AddHeader("Host", "api.instagram.com"); request.AddHeader("oauth_nonce", GenerateNonce(32)); request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Accept", "*/*"); request.AddHeader("User-Agent", "PostmanRuntime/7.18.0"); // Gets the response from the API request IRestResponse response = _client.Execute(request); //Parses the Json to the InstagramFeed model InstagramFeed feed = JsonConvert.DeserializeObject <InstagramFeed>(response.Content); return(feed); }
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); }
public void Initialize(Rendering rendering) { //Get current item var dataSource = rendering.DataSource; if (dataSource.IsNullOrEmpty()) { dataSource = Sitecore.Configuration.Settings.GetSetting("FeedsDataSource", "{AF7BCA0A-4C7F-4ACA-9956-E4801143775A}"); } CurrentItem = Sitecore.Context.Database.GetItem(dataSource); if (CurrentItem != null) { // Get all social feeds items var socialFeeds = CurrentItem.InnerItem.GetChildren().ToList(); FacebookApi = new FacebookApi(); TwitterApi = new TwitterApi(); InstagramApi = new InstagramApi(); YouTubeApi = new YouTubeApi(); PinterestApi = new PinterestApi(); FlickrApi = new FlickrApi(); if (socialFeeds.Any()) { // Get facebook feed item and bind facebook api class properties var facebookFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(FacebookFeed.TemplateId)); if (facebookFeedItem != null) { var facebookFeed = new FacebookFeed(facebookFeedItem); if (facebookFeed != null) { if (facebookFeed.FacebookAccount.TargetItem != null) { var facebookAccount = new FacebookAccount(facebookFeed.FacebookAccount.TargetItem); if (facebookAccount.SocialLink != null) { if (!ShowSocialFeed) { ShowSocialFeed = true; } FacebookApi.ApiId = string.Join("|", new string[] { facebookAccount.ApiId.Value, facebookAccount.ApiKey.Value }); FacebookApi.Icon = facebookAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(facebookAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; // new BaseFeed() FacebookApi.Priority = GetPriority(facebookFeed.BaseFeed); } } } } // Get twitter feed item and bind twitter api class properties var twitterFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(TwitterFeed.TemplateId)); if (twitterFeedItem != null) { var twitterFeed = new TwitterFeed(twitterFeedItem); if (twitterFeed != null) { if (twitterFeed.TwitterAccount.TargetItem != null) { var twitterAccount = new TwitterAccount(twitterFeed.TwitterAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } TwitterApi.HashTagsWithTokens = string.Join("|", new string[] { string.Join(",", twitterFeed.Hashtags.GetItems().Select(i => new Hashtag(i).Value.Value)), twitterAccount.TwitterToken.Value, twitterAccount.TwitterTokenSecret.Value, twitterAccount.TwitterConsumerKey.Value, twitterAccount.TwitterConsumerSecret.Value }); TwitterApi.Icon = twitterAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(twitterAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; TwitterApi.Priority = GetPriority(twitterFeed.BaseFeed); } } } // Get instagram feed item and bind instagram api class properties var instagramFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(InstagramFeed.TemplateId)); if (instagramFeedItem != null) { var instagramFeed = new InstagramFeed(instagramFeedItem); if (instagramFeed != null) { if (instagramFeed.InstagramAccount.TargetItem != null) { var instagramAccount = new InstagramAccount(instagramFeed.InstagramAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } InstagramApi.HashTags = string.Join(",", instagramFeed.Hashtags.GetItems().Select(i => new Hashtag(i).Value.Value)); InstagramApi.AccessToken = instagramAccount.AccessToken.Value; InstagramApi.ClientId = instagramAccount.InstagramClientId.Value; InstagramApi.Icon = instagramAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(instagramAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; InstagramApi.Priority = GetPriority(instagramFeed.BaseFeed); } } } // Get youtube feed item and bind youtube api class properties var youTubeFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(YoutubeFeed.TemplateId)); if (youTubeFeedItem != null) { var youTubeFeed = new YoutubeFeed(youTubeFeedItem); if (youTubeFeed.YouTubeAccount.TargetItem != null) { var youtubeAccount = new YoutubeAccount(youTubeFeed.YouTubeAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } YouTubeApi.AccountId = youtubeAccount.AccountId.Value; YouTubeApi.AccountApiKey = youtubeAccount.AccountApiKey.Value; YouTubeApi.Icon = youtubeAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(youtubeAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; YouTubeApi.Priority = GetPriority(youTubeFeed.BaseFeed); } } // Get pinterest feed item and bind pinterest api class properties var pinterestFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(PinterestFeed.TemplateId)); if (pinterestFeedItem != null) { var pinterestFeed = new PinterestFeed(pinterestFeedItem); if (pinterestFeed != null && pinterestFeed.PinterestAccount.TargetItem != null) { var pinterestAccount = new PinterestAccount(pinterestFeed.PinterestAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } PinterestApi.AccountId = pinterestAccount.AccountId.Value; PinterestApi.Icon = pinterestAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(pinterestAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; PinterestApi.Priority = GetPriority(pinterestFeed.BaseFeed); } } // Get flickr feed item and bind flickr api class properties var flickrFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(FlickrFeed.TemplateId)); if (flickrFeedItem != null) { var flickrFeed = new FlickrFeed(flickrFeedItem); if (flickrFeed != null) { if (flickrFeed.FlickrAccount.TargetItem != null) { var flickrAccount = new FlickrAccount(flickrFeed.FlickrAccount.TargetItem); if (!ShowSocialFeed) { ShowSocialFeed = true; } FlickrApi.AccountId = flickrAccount.AccountId.Value; FlickrApi.Icon = flickrAccount.SocialLink != null ? MediaManager.GetMediaUrl( new SocialMedia(flickrAccount.SocialLink.TargetItem).SocialIcon.MediaItem) : ""; FlickrApi.Priority = GetPriority(flickrFeed.BaseFeed); } } } } } }
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 int updateInstagramFeed(InstagramFeed fbfeed) { throw new NotImplementedException(); }
private static void GetParseInstagramSelfFeeds(string instagramId, string accessToken) { var instagramFeedRepo = new MongoRepository("InstagramFeed"); try { var _Media = new Media(); var usercmts = new InstagramResponse <Comment[]>(); var objComment = new CommentController(); string feeds = _Media.UserResentFeeds(instagramId, accessToken); if (feeds != null) { apiHitsCount++; JObject feed_data = JObject.Parse(feeds); foreach (var item in feed_data["data"]) { try { var objInstagramFeed = new InstagramFeed(); objInstagramFeed.FeedDate = Convert.ToDouble(item.SelectToken("created_time")?.ToString() ?? "0"); objInstagramFeed.FeedId = item.SelectToken("id")?.ToString(); objInstagramFeed.Type = item.SelectToken("type")?.ToString(); if (objInstagramFeed.Type == "video") { objInstagramFeed.VideoUrl = item.SelectToken("videos.standard_resolution.url")?.ToString(); } objInstagramFeed.FeedImageUrl = item.SelectToken("images.standard_resolution.url")?.ToString(); objInstagramFeed.InstagramId = instagramId; objInstagramFeed.LikeCount = Int32.Parse(item.SelectToken("likes.count")?.ToString() ?? "0"); objInstagramFeed.CommentCount = Int32.Parse(item.SelectToken("comments.count")?.ToString() ?? "0"); string str = item.SelectToken("user_has_liked")?.ToString(); if (str.ToLower() == "false") { objInstagramFeed.IsLike = 0; } else { objInstagramFeed.IsLike = 1; } objInstagramFeed.AdminUser = item.SelectToken("user.username")?.ToString(); objInstagramFeed.Feed = item.SelectToken("caption.text")?.ToString(); objInstagramFeed.ImageUrl = item.SelectToken("user.profile_picture")?.ToString(); objInstagramFeed.FromId = item.SelectToken("user.id")?.ToString(); objInstagramFeed.FeedUrl = item.SelectToken("link")?.ToString(); var lstInstagramComment = new List <InstagramComment>(); usercmts = objComment.GetComment(objInstagramFeed.FeedId, accessToken); for (int cmt = 0; cmt < usercmts.data.Count(); cmt++) { try { var objInstagramComment = new InstagramComment(); objInstagramComment.Comment = usercmts?.data[cmt]?.text ?? "0"; objInstagramComment.CommentDate = Convert.ToDouble(usercmts?.data[cmt]?.created_time.ToString() ?? "0"); objInstagramComment.CommentId = usercmts?.data[cmt]?.id ?? ""; objInstagramComment.FeedId = objInstagramFeed?.FeedId ?? ""; objInstagramComment.InstagramId = instagramId; objInstagramComment.FromName = usercmts?.data[cmt]?.from?.username ?? ""; objInstagramComment.FromProfilePic = usercmts?.data[cmt]?.from?.profile_picture ?? ""; lstInstagramComment.Add(objInstagramComment); } catch (Exception ex) { } } objInstagramFeed._InstagramComment = lstInstagramComment; var ret = instagramFeedRepo.Find <InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId)); var task = Task.Run(async() => { return(await ret); }); int count = task.Result.Count; if (count < 1) { instagramFeedRepo.Add(objInstagramFeed); } else { var filter = new BsonDocument("FeedId", objInstagramFeed.FeedId); var update = Builders <BsonDocument> .Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl).Set("_InstagramComment", objInstagramFeed._InstagramComment); instagramFeedRepo.Update <InstagramFeed>(update, filter); } } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } } } else { apiHitsCount = MaxapiHitsCount; } } catch (Exception ex) { apiHitsCount = MaxapiHitsCount; } }