public IEnumerable <SocialComment> Comments(ListItem item) { SocialFeedManager feedManager = new SocialFeedManager(_context); SocialFeedOptions feedOptions = new SocialFeedOptions(); ClientResult <SocialFeed> feed = feedManager.GetFeedFor(_context.Web.CurrentUser.LoginName, feedOptions); _context.ExecuteQuery(); foreach (SocialThread thread in feed.Value.Threads) { yield return(new SocialComment { Id = thread.Id, Text = thread.RootPost.Text }); foreach (SocialPost post in thread.Replies) { yield return(new SocialComment { Id = post.Id, Text = post.Text }); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { /* Save the Context Token and Host Web URL in hidden fields * These will be needed to create client contexts in subsequent calls */ hdnContextToken.Value = TokenHelper.GetContextTokenFromRequest(Page.Request); hdnHostWeb.Value = Page.Request["SPHostUrl"]; List<AssignmentPost> posts = new List<AssignmentPost>(); /* Create a collection of posts that mention the current user * and are tagged with #Assignment. These posts are candidates * to be turned into tasks for the current user */ using (ClientContext ctx = TokenHelper.GetClientContextWithContextToken(hdnHostWeb.Value, hdnContextToken.Value, Request.Url.Authority)) { try { //Get current user ctx.Load(ctx.Web, w => w.CurrentUser); ctx.ExecuteQuery(); //Get posts that mention the current user SocialFeedManager feedManager = new SocialFeedManager(ctx); ctx.Load(feedManager); SocialFeedOptions feedOptions = new SocialFeedOptions(); feedOptions.MaxThreadCount = 50; feedOptions.SortOrder = SocialFeedSortOrder.ByCreatedTime; ClientResult<SocialFeed> feedData = feedManager.GetMentions(false, feedOptions); ctx.ExecuteQuery(); //Build a collection of posts tagged with #Assignment foreach (SocialThread thread in feedData.Value.Threads) { if (thread.PostReference.Post.Text.Contains("#Assignment")) { AssignmentPost post = new AssignmentPost(); post.CreatedDate = thread.RootPost.CreatedTime; post.Body = thread.PostReference.Post.Text .Replace("#Assignment", string.Empty) .Replace("@" + ctx.Web.CurrentUser.Title, string.Empty); post.Requester = thread.Actors[thread.PostReference.Post.AuthorIndex].Name; posts.Add(post); } } //Bind these posts for display assignmentPosts.DataSource = posts; assignmentPosts.DataBind(); } catch (Exception x) { messages.Text = x.Message; } } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { /* Save the Context Token and Host Web URL in hidden fields * These will be needed to create client contexts in subsequent calls */ hdnContextToken.Value = TokenHelper.GetContextTokenFromRequest(Page.Request); hdnHostWeb.Value = Page.Request["SPHostUrl"]; List <AssignmentPost> posts = new List <AssignmentPost>(); /* Create a collection of posts that mention the current user * and are tagged with #Assignment. These posts are candidates * to be turned into tasks for the current user */ using (ClientContext ctx = TokenHelper.GetClientContextWithContextToken(hdnHostWeb.Value, hdnContextToken.Value, Request.Url.Authority)) { try { //Get current user ctx.Load(ctx.Web, w => w.CurrentUser); ctx.ExecuteQuery(); //Get posts that mention the current user SocialFeedManager feedManager = new SocialFeedManager(ctx); ctx.Load(feedManager); SocialFeedOptions feedOptions = new SocialFeedOptions(); feedOptions.MaxThreadCount = 50; feedOptions.SortOrder = SocialFeedSortOrder.ByCreatedTime; ClientResult <SocialFeed> feedData = feedManager.GetMentions(false, feedOptions); ctx.ExecuteQuery(); //Build a collection of posts tagged with #Assignment foreach (SocialThread thread in feedData.Value.Threads) { if (thread.PostReference.Post.Text.Contains("#Assignment")) { AssignmentPost post = new AssignmentPost(); post.CreatedDate = thread.RootPost.CreatedTime; post.Body = thread.PostReference.Post.Text .Replace("#Assignment", string.Empty) .Replace("@" + ctx.Web.CurrentUser.Title, string.Empty); post.Requester = thread.Actors[thread.PostReference.Post.AuthorIndex].Name; posts.Add(post); } } //Bind these posts for display assignmentPosts.DataSource = posts; assignmentPosts.DataBind(); } catch (Exception x) { messages.Text = x.Message; } } } }
protected void Page_Load(object sender, EventArgs e) { var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request); var hostWeb = Page.Request["SPHostUrl"]; using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority)) { SocialFeedManager feedManager = new SocialFeedManager(clientContext); clientContext.Load(feedManager); SocialFeedOptions feedOptions = new SocialFeedOptions(); ClientResult <SocialFeed> personalFeed = feedManager.GetFeed(SocialFeedType.Personal, feedOptions); ClientResult <SocialFeed> siteFeed = feedManager.GetFeedFor("https://swrightjet.sharepoint.com/ex2", feedOptions); ClientResult <SocialFeed> userFeed = feedManager.GetFeedFor("*****@*****.**", feedOptions); clientContext.ExecuteQuery(); DumpFeed("Personal Feed", personalFeed.Value); DumpFeed("Site Feed", siteFeed.Value); DumpFeed("User Feed", userFeed.Value); } }
private List <SocialPost> GetPosts(string accountName) { List <SocialPost> posts = new List <SocialPost>(); using (ClientContext ctx = TokenHelper.GetClientContextWithContextToken(hdnHostWeb.Value, hdnContextToken.Value, Request.Url.Authority)) { try { //Get posts SocialFeedManager feedManager = new SocialFeedManager(ctx); ctx.Load(feedManager); SocialFeedOptions feedOptions = new SocialFeedOptions(); feedOptions.MaxThreadCount = 50; feedOptions.SortOrder = SocialFeedSortOrder.ByCreatedTime; ClientResult <SocialFeed> feedData = feedManager.GetFeedFor(accountName, feedOptions); ctx.ExecuteQuery(); //Build a collection of posts foreach (SocialThread thread in feedData.Value.Threads) { SocialPost post = new SocialPost(); post.CreatedDate = thread.RootPost.CreatedTime; post.Body = thread.RootPost.Text; post.LikedByMe = thread.RootPost.LikerInfo.IncludesCurrentUser; posts.Add(post); } return(posts); } catch { return(new List <SocialPost>()); } } }
private List<SocialPost> GetPosts(string accountName) { List<SocialPost> posts = new List<SocialPost>(); using (ClientContext ctx = TokenHelper.GetClientContextWithContextToken(hdnHostWeb.Value, hdnContextToken.Value, Request.Url.Authority)) { try { //Get posts SocialFeedManager feedManager = new SocialFeedManager(ctx); ctx.Load(feedManager); SocialFeedOptions feedOptions = new SocialFeedOptions(); feedOptions.MaxThreadCount = 50; feedOptions.SortOrder = SocialFeedSortOrder.ByCreatedTime; ClientResult<SocialFeed> feedData = feedManager.GetFeedFor(accountName, feedOptions); ctx.ExecuteQuery(); //Build a collection of posts foreach (SocialThread thread in feedData.Value.Threads) { SocialPost post = new SocialPost(); post.CreatedDate = thread.RootPost.CreatedTime; post.Body = thread.RootPost.Text; post.LikedByMe = thread.RootPost.LikerInfo.IncludesCurrentUser; posts.Add(post); } return posts; } catch { return new List<SocialPost>(); } } }
private void btnGetFeeds_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(txtUsername.Text)) { try { Deployment.Current.Dispatcher.BeginInvoke(() => { lstFeeds.Items.Clear(); }); // Create the client context object. context = new ClientContext(Office365.Office365SiteUrl); // Create an instance of Authenticator object. Authenticator at = new Authenticator(); // Set AuthenticationMode for SharePoint Online. at.AuthenticationMode = ClientAuthenticationMode.MicrosoftOnline; at.CookieCachingEnabled = true; // Assign the instance of Authenticator object to the ClientContext.Credential property. context.Credentials = at; string targetUser = txtUsername.Text; // Create an instance of SocialFeedManager. SocialFeedManager feedManager = new SocialFeedManager(context); context.Load(feedManager, f => f.Owner); SocialFeedOptions feedOptions = new SocialFeedOptions(); feedOptions.MaxThreadCount = 10; // Get feeds for the target user. ClientResult <SocialFeed> targetUserFeed = feedManager.GetFeedFor(targetUser, feedOptions); feedOptions.SortOrder = SocialFeedSortOrder.ByCreatedTime; context.ExecuteQueryAsync( (object obj, ClientRequestSucceededEventArgs args) => { // Success Logic. owner = feedManager.Owner.Name; // Iterate through the feeds of target user. IterateThroughFeed(targetUserFeed.Value, SocialFeedType.Personal); }, (object obj, ClientRequestFailedEventArgs args) => { // Failure Logic. Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("Error: " + args.Message); }); }); } catch (Exception ex) { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("Error: " + ex.Message); }); } } else { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("Enter the target username whose feeds you want to retrieve"); }); } }