Share-n-dipity

SharePoint serendipity is the effect by which one accidentally discovers something fortunate, especially while looking for something else entirely. In this case, it is the occassional musings, observations, and Ouija board readings about the phabulously

Find Out Who’s Following You with SharePoint 2010 Social Features

Find Out Who’s Following You with SharePoint 2010 Social Features

  • Comments 2
  • Likes

One of the things I’ve wondered about off and on is how to find out who is following a certain person using the new social features of SharePoint 2010.  For example, when I go to the My Site of somebody I can click on the Colleagues tab and I can see all of the people that person is following.  But what, for example, if I want to run a query and see who all is following me?  Or following Jimmy?  Or whomever.

UPDATE:  I got a great new way to do this from some other folks on the SharePoint team.  This post now uses that method.

To start out with, we’ll get the profile of the person we’re tracking – that is, we want to see who is following this person:

string acctName = "vbtoys\\sjackson"; //we want to see who is following this person

 

UserProfileManager upm = new UserProfileManager(ctx);

 

UserProfile up = upm.GetUserProfile(acctName);

 

 

Next we’re going to create a new instance of the ActivityManager class.  We’re going to pass in the UserProfile and SPServiceContext that we used with the UserProfileManager class to create this instance:

 

ActivityManager am = new ActivityManager(up, ctx);

 

 

Now we’re going to create three variables – one to hold a list of people we want to track (just one person in this case), and two to hold the return values that were found.  In my limited testing I’ve found that the owners variable contains only the UserProfile person.  It’s the colleaguesOfOwners variable that’s really interesting:

 

List<long> bulkRecordIds = new List<long>();

Dictionary<long, MinimalPerson> owners = new Dictionary<long, MinimalPerson>();

Dictionary<long, List<MinimalPerson>> colleaguesOfOwners =

new Dictionary<long,List<MinimalPerson>>();

 

//add the ID of the person I'm tracking

bulkRecordIds.Add(up.RecordId);

 

 

Now we have all the data points we need to make our query.  We do that with the static method GetUsersColleaguesAndRights method on the ActivityFeedGatherer class:

 

ActivityFeedGatherer.GetUsersColleaguesAndRights(am, bulkRecordIds,

out owners, out colleaguesOfOwners);

 

 

Now that we have the results, we can enumerate through the list of colleagues that it found.  These are all people that are following the account we specified in the acctName string var earlier:

 

foreach (long key in colleaguesOfOwners.Keys)

{

List<MinimalPerson> l = colleaguesOfOwners[key];

 

       foreach (MinimalPerson mp in l)

       {

       Debug.WriteLine(mp.AccountName);

       }

}

 

And there you have it – all the people who are following a particular person.

 

Attachment: Find Out Who.docx
Comments
Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment