/// <addFacebookFeed> /// add new Facebook Feed /// </summary> /// <param name="fbfeed">Set Values in a Facebook feed Class Property and Pass the Object of Facebook feed Class (SocioBoard.Domain.Facebookfeed).</param> public void addFacebookFeed(FacebookFeed fbfeed) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //Begin session trasaction and opens up. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Procees action, to save new data. session.Save(fbfeed); transaction.Commit(); } //End Trasaction } //End session }
public FacebookFeed GetFeed() { try { var url = String.Format(facebookFeedUrl, this.FacebookAppId, this.FacebookAccessToken); var responseMessage = client.GetAsync(url).Result; var body = responseMessage.Content.ReadAsStringAsync().Result; var jsonData = FacebookFeed.FromJson(body); return(jsonData); } catch (Exception e) { throw e; } }
public async void MakeRequestForFacebookFeed() { var credentials = TestSettings.GetToken <Facebook, OAuth2Credentials>(); if (credentials.IsTokenExpired) { throw new Exception("Expired credentials!!!"); } var request = new FacebookFeed() { Since = DateTime.Today.Subtract(TimeSpan.FromDays(500)), Until = DateTime.Today, Limit = 10 }; var response = await new OAuthRequester(credentials) .MakeOAuthRequestAsync <FacebookFeed, FacebookFeedResponse>(request) .ConfigureAwait(false); Assert.NotNull(response); }
// Saving FacebookFeeds of user into database i.e. FacebookFeed Table public void getFacebookUserFeeds(dynamic data, dynamic profile) { FacebookFeed fbfeed = new FacebookFeed(); User user = (User)HttpContext.Current.Session["LoggedUser"]; FacebookFeedRepository fbfeedrepo = new FacebookFeedRepository(); if (data != null) { foreach (var result in data["data"]) { fbfeed.Type = "fb_feed"; try { fbfeed.UserId = user.Id; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbfeed.ProfileId = profile["id"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { fbfeed.Id = Guid.NewGuid(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } fbfeed.FromProfileUrl = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small"; fbfeed.FromName = result["from"]["name"].ToString(); fbfeed.FromId = result["from"]["id"].ToString(); fbfeed.FeedId = result["id"].ToString(); fbfeed.FeedDate = DateTime.Parse(result["created_time"].ToString()); fbfeed.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments"; fbfeed.FbLike = "http://graph.facebook.com/" + result["id"] + "/likes"; string message = string.Empty; int lstfbcount = 0; if (lstfbcount < 25) { try { if (result["message"] != null) { message = result["message"]; lstfbcount++; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); try { if (result["description"] != null) { message = result["description"]; lstfbcount++; } } catch (Exception exx) { try { Console.WriteLine(exx.StackTrace); if (result["story"] != null) { message = result["story"]; lstfbcount++; } } catch (Exception exxx) { Console.WriteLine(exxx.StackTrace); message = string.Empty; } } } } fbfeed.FeedDescription = message; fbfeed.EntryDate = DateTime.Now; if (!fbfeedrepo.checkFacebookFeedExists(fbfeed.FeedId)) { fbfeedrepo.addFacebookFeed(fbfeed); } } } }
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 string getFacebookpageFeeds(dynamic data, dynamic profile) { FacebookFeed fbfeed = new FacebookFeed(); User user = (User)HttpContext.Current.Session["LoggedUser"]; FacebookFeedRepository fbfeedrepo = new FacebookFeedRepository(); string fanpost = string.Empty; if (data != null) { foreach (var result in data["data"]) { string message = string.Empty; int likecount = 0; int lstfbcount = 0; int commentcount = 0; int talking = 0; string sharecount = string.Empty; try { if (result["message"] != null) { message = result["message"]; try { if (result["likes"]["data"] != null) { foreach (var item in result["likes"]["data"]) { if (item != null) { likecount++; } else { likecount = 0; } } } else { likecount = 0; } } catch (Exception ex) { likecount = 0; } try { if (result["comments"]["data"] != null) { foreach (var item in result["comments"]["data"]) { if (item != null) { commentcount++; } else { commentcount = 0; } } } else { commentcount = 0; } } catch (Exception ex) { commentcount = 0; } try { if (result["shares"]["count"] != null) { sharecount = result["shares"]["count"].ToString(); } else { sharecount = "0"; } } catch (Exception ex) { sharecount = "0"; } // lstfbcount++; } fanpost = fanpost + "<div class=\"message-sent-table\" ><div class=\"labe-1\">" + message + "</div>" + "<div class=\"labe-4\">" + talking + "</div><div class=\"labe-5\">" + likecount + "</div><div class=\"labe-6\">" + commentcount + "</div><div class=\"labe-5\">" + sharecount + "</div></div>"; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } //fanpost = fanpost + "<div class=\"message-sent-table\" ><div class=\"labe-1\">" + message + "</div>" + // "<div class=\"labe-4\">" + talking + "</div><div class=\"labe-5\">" + likecount + "</div><div class=\"labe-6\">" + commentcount + "</div><div class=\"labe-5\">" + sharecount + "</div></div>"; } } return(fanpost); }
public int updateFacebookFeed(FacebookFeed fbfeed) { throw new NotImplementedException(); }