Question

We currently have groups of users that we'd like to push news out to their newsfeed. Obviously, their newsfeed is personal, but we've been selling it as the one stop shop for news pertinent for them. But this would require users to go around and follow all the announcements / blogs / etc. that we'd like to push their way.

Is there a way to change what a user follows without being that person?

Update Here's the eventual code I wrote inside a web service deployed to the farm. This code works for making a user follow a site, a document, tag, or user. It doesn't get a user to get notifications for a document library. I believe that would an alert setting somewhere. But I thought I'd post some code for others in case they needed this functionality.

var web = SPContext.Current.Web;
            web.AllowUnsafeUpdates = true;
            using (var site = SPContext.Current.Site) {

                SPUtility.ValidateFormDigest();
                SPSecurity.RunWithElevatedPrivileges(delegate() {

                    var spServiceContext = SPServiceContext.GetContext(site);
                    var profileManager = new Microsoft.Office.Server.UserProfiles.UserProfileManager(spServiceContext);
                    var userProfile = profileManager.GetUserProfile(parameters.username);
                    var followingManager = new Microsoft.Office.Server.Social.SPSocialFollowingManager(userProfile, spServiceContext);
                    var socialActor = new Microsoft.Office.Server.Social.SPSocialActorInfo();

                    socialActor.ContentUri = new System.Uri(parameters.listUrl);
                    socialActor.AccountName = userProfile.AccountName;
                    switch (parameters.urlType) {
                        case "site": socialActor.ActorType = Microsoft.Office.Server.Social.SPSocialActorType.Site; break;
                        case "document": socialActor.ActorType = Microsoft.Office.Server.Social.SPSocialActorType.Document; break;
                        case "user": socialActor.ActorType = Microsoft.Office.Server.Social.SPSocialActorType.User; break;
                        case "tag": socialActor.ActorType = Microsoft.Office.Server.Social.SPSocialActorType.Tag; break;
                    }

                    ret += "FollowingManagerMore: " + followingManager.FollowedSitesUri.ToString() + "<br/>";
                    if (!followingManager.IsFollowed(socialActor)) {
                        followingManager.Follow(socialActor);
                    }
                });

and the service contract part looks like this:

 [OperationContract]
        [WebInvoke(Method="POST", RequestFormat = WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Bare)]
        string MakeUserFollow(UseFollowParameters parameters);
Was it helpful?

Solution

It appears you are not the first person to have this requirement. Here is an example from http://blog.areflyen.no/2014/04/04/following-sites-using-powershell-and-the-social-api-in-sharepoint-2013/ using PowerShell to force all users to follow a site:

# Get UserProfile Manager
$site = Get-SPSite -Limit 1
$serviceContext = Get-SPServiceContext($site)
$profileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)
$profiles = $profileManager.GetEnumerator()

# Iterates through all the user profiles
foreach ($profile in $profiles)
{
    $followingManager = New-Object Microsoft.Office.Server.Social.SPSocialFollowingManager($profile)

    # Create a new social actor object for the site to follow
    $socialActor = New-Object Microsoft.Office.Server.Social.SPSocialActorInfo
    $socialActor.ContentUri = "http://intranet/sites/important-news-from-corp" # REPLACE THIS WITH YOUR SITE
    $socialActor.ActorType = [Microsoft.Office.Server.Social.SPSocialActorType]::Site

    # Follow the mandatory site
    if (!$followingManager.IsFollowed($socialActor))
    {
        $followingManager.Follow($socialActor)
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top