In the last post, I have shown how to list the user’s personal SharePoint 2013 feed. Here is the code snipped for getting the data from the site feed:
using (SPSite site = new SPSite(siteName))
{
using (SPWeb web = site.OpenWeb())
{
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile userProfile = profileManager.GetUserProfile(username);
//get the Social Feed Manager of the current user
SPSocialFeedManager feedManager = new SPSocialFeedManager(userProfile, context);
SPSocialFeedOptions options = new SPSocialFeedOptions()
{
MaxThreadCount = 5
};
SPSocialFeed feed = feedManager.GetFeedFor(theSite, options);
foreach (SPSocialThread thread in feed.Threads)
{
SPSocialThread fullThread = feedManager.GetFullThread(thread.Id);
Console.WriteLine(string.Format(" Thread: {0} Source: {1} ", fullThread.RootPost.Text, fullThread.RootPost.Source.Text));
Console.WriteLine(string.Format(" {0}", fullThread.Id));
Console.WriteLine("");
foreach (var reply in fullThread.Replies)
{
Console.WriteLine(string.Format(" Reply: {0} Source: {1} ", reply.Text, reply.Source.Text));
Console.WriteLine(string.Format(" {0}", reply.Id));
Console.WriteLine("");
}
}
Console.WriteLine("");
}
}