I've been banging my head against this for a little while now. Following this SDK, I try to add an item to a users NewsFeed and retrieve that item. It seems the SDK is lacking some middle steps in their Blog example and I tried to fill it in with what I think should bear results.
Here is the code I am working with. Please note I added what I thought was needed.
IUser user = CommunitySystem.CurrentContext.DefaultSecurity.GetUsersByAlias("newsfeedadmin")[0];
UserAuthor author = new UserAuthor(user);
Blog userBlog = new Blog("This be my blog", "This be my body text", author);
userBlog = BlogHandler.Instance.AddBlog(userBlog); // Add to database, returns object with database vars set
Entry userBlogEntry = new Entry(userBlog, "My Entry", "Entry text", author);
userBlogEntry = BlogHandler.Instance.AddEntry(userBlogEntry); // Add to database, returns object with database vars set
NewsFeedAction addedBlogEntryAction = NewsFeedHandler.Instance.GetAction("Added this blog to the site!");
if(addedBlogEntryAction == null)
{
addedBlogEntryAction = new NewsFeedAction("Added this blog to the site!", NewsFeedActionCapability.None);
addedBlogEntryAction = NewsFeedHandler.Instance.AddAction(addedBlogEntryAction); // Add to database, returns object with database vars set
}
NewsFeedStory addedBlogEntryStory = new NewsFeedStory(addedBlogEntryAction, author, null, userBlogEntry);
addedBlogEntryStory = NewsFeedHandler.Instance.AddStory(addedBlogEntryStory); // Add to database, returns object with database vars set
// Get a NewsFeed for user
NewsFeed newsFeed = NewsFeedHandler.Instance.GetNewsFeedByUser(user, NewsFeedType.MiniFeed);
if (newsFeed == null)
newsFeed = NewsFeedHandler.Instance.AddNewsFeed(new NewsFeed(NewsFeedType.MiniFeed, user));
NewsFeedHandler.Instance.PublishStory(newsFeed, addedBlogEntryStory);
I create a Blog, create an Entry with the Blog in it and commit it with the BlogHandler. Next I get or create a NewsFeedAction, then create a NewsFeedStory with the action and Entry in it, and commit it with NewsFeedHandler. Next I get the user's MiniFeed or create a new one and Publish it.
After this, following the SDK, I attempt to get the MiniFeed that I created, which returns an empty IEnumerable.
var user = CommunitySystem.CurrentContext.DefaultSecurity.GetUsersByAlias("newsfeedadmin")[0];
DateTime startTime = new DateTime(2015, 1, 1);
DateTime stopTime = new DateTime(2015, 1, 29);
int totalItems;
NewsFeedStoryCollection actorStories = NewsFeedHandler.Instance.GetNewsFeedStories(NewsFeedType.MiniFeed, EPiServer.Common.EntityStatus.Approved, user, null, startTime, stopTime, 1, 10, out totalItems);
I found that the database is adding data to the MiniFeed table with blnIsPublished set to 0. Not sure what other calls to make. Also, I tried using both the MiniFeed and NewsFeed, but still same results.
Hi,
I've been banging my head against this for a little while now. Following this SDK, I try to add an item to a users NewsFeed and retrieve that item. It seems the SDK is lacking some middle steps in their Blog example and I tried to fill it in with what I think should bear results.
Here is the code I am working with. Please note I added what I thought was needed.
I create a Blog, create an Entry with the Blog in it and commit it with the BlogHandler. Next I get or create a NewsFeedAction, then create a NewsFeedStory with the action and Entry in it, and commit it with NewsFeedHandler. Next I get the user's MiniFeed or create a new one and Publish it.
After this, following the SDK, I attempt to get the MiniFeed that I created, which returns an empty IEnumerable.
I found that the database is adding data to the MiniFeed table with blnIsPublished set to 0. Not sure what other calls to make. Also, I tried using both the MiniFeed and NewsFeed, but still same results.
Am I missing a step?
Thanks,
Brandon