Follow content in SharePoint

Learn about common programming tasks for following content (documents, sites, and tags) in SharePoint.

APIs for following content in SharePoint

When users follow documents, sites, or tags, status updates from documents, conversations on sites, and notifications of tag use show up in their newsfeed. The features related to following content can be seen on the Newsfeed and the Following content pages.

SharePoint provides the following APIs that you can use to programmatically follow content:

  • Client object models for managed code

    • .NET client object model

    • Silverlight client object model

    • Mobile client object model

  • JavaScript object model

  • Representational State Transfer (REST) service

  • Server object model

As a best practice in SharePoint development, use client APIs when you can. Client APIs include the client object models, a JavaScript object model, and a REST service. For more information about the APIs in SharePoint and when to use them, see Choose the right API set in SharePoint.

Each API includes a manager object that you use to perform core tasks for following content.

Note: The same APIs are used to follow people. See Follow people in SharePoint for an overview of Following People tasks.

Table 1 shows the manager and other key objects (or REST resources) in the APIs and the class library (or access point) where you can find them.

Note: The Silverlight and mobile client object models are not included in Table 1 or Table 2 because they provide the same core functionality as the .NET client object model and use the same signatures. The Silverlight client object model is defined in Microsoft.SharePoint.Client.UserProfiles.Silverlight.dll, and the mobile client object model is defined in Microsoft.SharePoint.Client.UserProfiles.Phone.dll.

Table 1. SharePoint APIs used for following content programmatically

API Key objects
.NET client object model
See: How to: Follow documents and sites by using the .NET client object model in SharePoint
Manager object: SocialFollowingManager
Primary namespace: Microsoft.SharePoint.Client.Social
Other key objects: SocialActor , SocialActorInfo , SocialActorType , SocialActorTypes
Class library: Microsoft.SharePoint.Client.UserProfiles.dll
JavaScript object model Manager object: SocialFollowingManager
Primary namespace: SP.Social
Other key objects: SocialActor, SocialActorInfo, SocialActorType, SocialActorTypes
Class library: SP.UserProfiles.js
REST service
See How to: Follow documents, sites, and tags by using the REST service in SharePoint
Manager resource: social.following
Primary namespace (OData): sp.social.SocialRestFollowingManager
Other key resources: SocialActor, SocialActorInfo, SocialActorType, SocialActorTypes
Access point: <siteUri>/_api/social.following
Server object model Manager object: SPSocialFollowingManager
Primary namespace: Microsoft.Office.Server.Social
Other key objects: SPSocialActor , SPSocialActorInfo , SPSocialActorType , SPSocialActorTypes
Class library: Microsoft.Office.Server.UserProfiles.dll

Common programming tasks for following content in SharePoint

Table 2 shows common programming tasks for following content and the members that you use to perform them. Members are from the .NET client object model (CSOM), JavaScript object model (JSOM), REST service, and server object model (SSOM).

Note: The same APIs are used to follow people. See Follow people in SharePoint for an overview of Following People tasks.

Table 2. API for common tasks for following content in SharePoint

Task Members
Create an instance of a manager object in the context of the current user CSOM: SocialFollowingManager
JSOM: SocialFollowingManager
REST: <siteUri>/_api/social.following
SSOM: SPSocialFollowingManager
Create an instance of a manager object in the context of a specified user CSOM: not implemented
JSOM: not implemented
REST: not implemented
SSOM: SPSocialFollowingManager (overloaded)
Have the current user start following (stop following) an item CSOM: Follow ( StopFollowing )
JSOM: follow ( stopFollowing)
REST: POST <siteUri>/_api/social.following/Follow ( <siteUri>/_api/social.following/StopFollowing) and pass the actor parameter in the request body
SSOM: Follow ( StopFollowing )
Find out whether the current user is following a particular item CSOM: IsFollowed
JSOM: isFollowed
REST: POST <siteUri>/_api/social.following/IsFollowed and pass the actor parameter in the request body
SSOM: IsFollowed
Get the documents, sites, and/or tags that the current user is following CSOM: GetFollowed
JSOM: getFollowed
REST: GET <siteUri>/_api/social.following/my/Followed(types=2) (documents = 2, sites = 4, tags = 8.md)
SSOM: GetFollowed
Get the count of documents, sites, and/or tags that the user is following CSOM: GetFollowedCount
JSOM: getFollowedCount
REST: GET <siteUri>/_api/social.following/my/FollowedCount(types=2) (documents = 2, sites = 4, tags = 8.md)
SSOM: GetFollowedCount
Get the URI of the site that lists the current user's followed documents CSOM: FollowedDocumentsUri
JSOM: followedDocumentsUri
REST: GET <siteUri>/_api/social.following/my/FollowedDocumentsUri
SSOM: FollowedDocumentsUri
Get the URI of the site that lists the current user's followed sites CSOM: FollowedSitesUri
JSOM: followedSitesUri
REST: GET <siteUri>/_api/social.following/my/FollowedSitesUri
SSOM: FollowedSitesUri

Note: For examples that show how to use the REST service to follow content, see How to: Follow documents, sites, and tags by using the REST service in SharePoint.

How to get a tag's GUID based on the tag's name by using the JavaScript object model

To start and stop following a tag or to find out whether the current user is following it, you need to use the tag's GUID. The following code shows how to get the GUID based on the tag name.

Before you run the code, you need to add a reference to sp.taxonomy.js and change the placeholder tag name with the name of an existing tag.


function getTagGuid() {
    var tagName = '#tally';
    var clientContext = new SP.ClientContext.get_current();
    var label = SP.Taxonomy.LabelMatchInformation.newObject(clientContext);
    label.set_termLabel(tagName);
    label.set_trimUnavailable(false);
    var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(clientContext);
    var termStore = taxSession.getDefaultKeywordsTermStore();
    var termSet = termStore.get_hashTagsTermSet();
    terms = termSet.getTerms(label);
    clientContext.load(terms);
    clientContext.executeQueryAsync(
        function () {
            var tag = terms.get_item(0);
            if (tag !== null) {
                var tagGuid = tag.get_id().toString();
                if (!SP.ScriptUtility.isNullOrEmptyString(tagGuid)) {
                    alert(tagGuid);
                }
            }
        },
        function (sender, args) {
            alert(args.get_message());
        }
    );
}

Additional resources