7

I wanted to get a list of all users who are following a specific site. I have looked in to SocialFollowing Manager (http://msdn.microsoft.com/en-us/library/jj163133.aspx) and it seems to provide the details from user's perspective.

Is there any api call where-in I can get list of users following a site?

I am using SharePoint 2013 standard server edition.

/Sharath

2

I think you cannot. Everything turns around the user.

The only way now I can figure out is to fetch each user profile and using SPSocialActor class getting if site is followed by that user. If the site is followed you can add the user to a list of users (List) with properties as imgUrl, name, surname, etc.

Try this (I have not tested it) but I am not sure if this will work but you can follow this approach

SPSite currentSite = SPContext.Current.Site;
SPServiceContext contexto = SPServiceContext.GetContext(currentSite);

UserProfileManager perfiles = new UserProfileManager(contexto);

foreach (UserProfile userProfile in perfiles)
{
    try
    {
         //Check if the user profile is already created
         if (userProfile.PersonalSiteInstantiationState == PersonalSiteInstantiationState.Created)
         {
             SPSocialFollowingManager followingManager = new SPSocialFollowingManager(userProfile, contexto);
             //Get the sites followed by the user
             SPSocialActor[] followedUserSites = followingManager.GetFollowed(SPSocialActorTypes.Sites);
             //now get if the site is in followedUserSites array
             SPSocialActor matchSite = followedUserSites.Where(st => st.Uri.AbsoluteUri.Contains(currentSite.Url)).SingleOrDefault();
             if (matchSite != null)
             {
                 //Add logic to your custom object or whatever
             }
         }
    }
    catch(Exception ex)
    {
    }
}

Hope it helps

2
  • Note that this process could be slow if you have a lot of user profiles
    – Alvmad
    Jul 30 '13 at 11:05
  • Thanks, as you have mentioned this will be a long process. Maybe if I don't get anything I might choose to use this brute force method as a timer job. Jul 30 '13 at 18:17
0

As far as I know, this is not possible using the Client Object Model or REST API. I am guessing you are using that from the link you provided.

0

Iterate through all provisioned Personal Sites and retrieve all info regarding followed sites per user:

Simple PS Script code sample

$PersonalSite = Get-SPSite URL
$oSocialList = $PersonalSite.RootWeb.Lists["Social"]
$query = New-Object Microsoft.SharePoint.SPQuery
$query.Folder = $oSocialList.RootFolder.SubFolders["Private"].SubFolders["FollowedSites"]
$FollowedSitesItems = $oSocialList.GetItems($query)
foreach($FollowedSite in $FollowedSitesItems){
   write-host $FollowedSite["ows_Url"]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.