SharePoint 2013 - Get Personal Site News Feed Thread ID From Search Results

I’m trying to build an App that allows a group of people to get reports on my site news feed for any inappropriate words.  


However, I soon realized that the way to compile Thread ID is different for site news feed and personal site news feed.  Typical personal site news feed thread ID would look like below (from HTML source of personal site news feed page):

1.527d55a9388047439ee30c11b71e3650.a5c4bd89f0314468b1c887ed3a76f70e.725153485bc24e969fd4aba69179920d.0c37852b34d0418e91c62ac25af4be5b.1397059c08e54b95b7de51056f4e94fb.27.27.S-1-5-21-1481920619-292190258-1324514410-864729

It’s in this format [ActorId].[RootPostUniqueID].[RootPostID].[ListItemID].[SID]  The first 5 parts are the actor ID (I can’t figure out exactly what’s used to build this Actor ID.  The last part of the Actor ID seems to be PartitionId from the search result.

In the post above, it says to use

{RootPostOwnerID}.{RootPostUniqueID}.{RootPostID}.{ListItemID}.1

to generate the Thread ID.  But the RootPostOwnerID for the personal news feed is the users’ ID (i.e. domain\account).  So, it is obviously not going to work.

After some investigate, I figured out that it should be something like this (but not exactly as I’ll explain more details later).

[SPS-FeedIdentifier].[RootPostUniqueID].[ListItemID].[ListItemID].[SID] - root post
[SPS-FeedIdentifier].[RootPostUniqueID].[RootPostID].[ListItemID].[SID] – reply


[SPS-FeedIdentifier] and [SID] are properties for user profile.  So basically, you’ll have to use RootPostOwnerID value (domain\account) from the search result and get the UserProfile object and then get SPS-FeedIdentifier value.

String ActorID = result["RootPostOwnerID"].ToString();

if (ActorID.Contains('\\'))
{
PeopleManager peopleManager = new PeopleManager(clientContext);
PersonProperties personProperties = peopleManager.GetPropertiesFor(ActorID);

clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
clientContext.ExecuteQuery();

String SPSFeedIdentifier = personProperties.UserProfileProperties["SPS-FeedIdentifier"];
String SID = personProperties.UserProfileProperties["SID"];

}

The SPS-FeedIdentifier will have value looks like
http://mysiteurl/personal/user1;1.527d55a9388047439ee30c11b71e3650.a5c4bd89f0314468b1c887ed3a76f70e.bb0a7a13256f4b41b29c2477aab81590.0c37852b34d0418e91c62ac25af4be5b]

and you can parse out the part after ‘;’ to get the actor ID.

If things would be this simple, then it wouldn’t be developing for SharePoint and wouldn’t be fun.  The series of string that you got from SPS-FeedIdentifier is closed but not exactly the Actor ID.

The fourth part of the string has to be replace by UserProfile_GUID property value (need to remove the ‘-‘ in the guid).

Break down the series string from SPS-FeedIdentifier, you’ll get

1.
527d55a9388047439ee30c11b71e3650.
a5c4bd89f0314468b1c887ed3a76f70e.
bb0a7a13256f4b41b29c2477aab81590. (need to be replace with UserProfile_GUID but without '-')
0c37852b34d0418e91c62ac25af4be5b (this is the PartitionId)


Once you replace the fourth part with UserProfile_GUID (let’s call it UpdatedIdentifier), the Thread ID format becomes

[UpdatedIdentifier].[RootPostUniqueID].[ListItemID].[ListItemID].[SID] - root post
[UpdatedIdentifier].[RootPostUniqueID].[RootPostID].[ListItemID].[SID] – reply



This is the Thread ID you can use with SocialFeedManager to get the full thread.

Comments

Fred said…
Thank you for this awesome article.
We had exactly the same problem in our SharePoint environment and it would be very hard to find this trick out for myself.

Popular posts from this blog

SharePoint 2013 App Details Page Error

SharePoint 2013 - Working with Display Template for Content Search Web Part

Add spell check dictionary in SharePoint 2010, SharePoint 2013, and Office 365