Work with social feeds in SharePoint

Learn about common programming tasks for working with social feeds and microblog posts in SharePoint.

APIs for working with social feeds in SharePoint

In SharePoint on-premises farms, interactive social feeds are designed to encourage people to share information and to stay connected with people and content. You can see many of the feed features on the Newsfeed page on a user's personal site. Feeds contain collections of threads that represent microblog posts, conversations, status updates, and other notifications.

SharePoint provides the following APIs that you can use to programmatically work with social feeds:

  • 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, the JavaScript object model, and the 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 feed-related tasks. Table 1 shows the manager and other key objects (or REST resources) in the APIs and the class library (or endpoint URI) where you can find them.

Note

The Silverlight and mobile client object models are not explicitly mentioned 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 working with social feeds programmatically

API Key objects
.NET client object model
See: How to: Create and delete posts and retrieve the social feed by using the .NET client object model in SharePoint
Manager object: SocialFeedManager
Primary namespace: Microsoft.SharePoint.Client.Social
Other key objects: SocialFeed , SocialThread , SocialPost , SocialPostCreationData , SocialFeedOptions , SocialActor
Class library: Microsoft.SharePoint.Client.UserProfiles.dll
JavaScript object model
See How to: Create and delete posts and retrieve the social feed by using the JavaScript object model in SharePoint
Manager object: SocialFeedManager
Primary namespace: SP.Social
Other key objects: SocialFeed, SocialThread, SocialPost, SocialPostCreationData, SocialFeedOptions, SocialActor
Class library: SP.UserProfiles.js
REST service
See How to: Learn to read and write to the social feed by using the REST service in SharePoint
Manager resource: social.feed (SocialRestFeedManager)
Primary namespace (OData): SP.Social
Other key resources: SocialFeed, SocialRestFeed, SocialThread, SocialRestThread, SocialPost, SocialPostCreationData, SocialRestPostCreationData, SocialFeedOptions, SocialActor, SociaRestActor
Access point: <siteUri>/_api/social.feed
Server object model
Note: Code that uses the server object model to access feed data and runs remotely must use an SPServiceContextScope object.
Manager object: SPSocialFeedManager
Primary namespace: Microsoft.Office.Server.Social
Other key objects: SPSocialFeed , SPSocialThread , SPSocialPost , SPSocialFeedOptions , SPSocialActor
Class library: Microsoft.Office.Server.UserProfiles.dll

If you're using the server object model to access feed content and your code isn't running in a SharePoint instance (in other words, if your extension is not installed in the LAYOUTS folder on the application server), use an SPServiceContextScope object in your code. The following code example shows one way to incorporate the SPServiceContextScope object into your code.


using (SPSite site = new SPSite(<siteURL>))
{
    using (new Microsoft.SharePoint.SPServiceContextScope(SPServiceContext.GetContext(site)))
    {
        // code
    }
}

Common programming tasks for working with social feeds in SharePoint

Table 2 shows common programming tasks for working with social feeds 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).

Table 2. API for common programming tasks for working with social feeds in SharePoint

Task Members
Create an instance of the manager object in the context of the current user CSOM: SocialFeedManager
JSOM: SocialFeedManager
REST: GET <siteUri>/_api/social.feed
SSOM: SPSocialFeedManager
Create an instance of the manager object in the context of a particular user CSOM: not implemented
JSOM: not implemented
REST: not implemented
SSOM: SPSocialFeedManager
Get the user for the current context CSOM: Owner
JSOM: owner
REST: GET <siteUri>/_api/social.feed/my
SSOM: Owner
Get the feed for the current user
(specify the feed type)
CSOM: GetFeed
JSOM: getFeed
REST: GET <siteUri>/_api/social.feed/my/Feed (personal feed.md), <siteUri>/_api/social.feed/my/News, <siteUri>/_api/social.feed/my/TimelineFeed, or <siteUri>/_api/social.feed/my/Likes
SSOM: GetFeed
Get the personal feed for a particular user CSOM: GetFeedFor
JSOM: getFeedFor
REST: GET <siteUri>/_api/social.feed/actor(item='domain\\user')/Feed
SSOM: GetFeedFor
Get the site feed for a team site
(specify the URL of the site feed as the actor (example: http://<siteCollection>/<teamSite>/newsfeed.aspx))
CSOM: GetFeedFor
JSOM: getFeedFor
REST: GET <siteUri>/_api/social.feed/actor(item=@v)/Feed?@v='http://<siteCollection>/<teamSite>/newsfeed.aspx'
SSOM: GetFeedFor
Publish a root post to the current user's feed
(specify null for the target)
CSOM: CreatePost
JSOM: createPost
REST: POST <siteUri>/_api/social.feed/my/Feed/Post and pass the restCreationData parameter in the request body
SSOM: CreatePost
Publish a post to a site feed
(specify the URL of the site feed as the target (example: http://<siteCollection>/teamSite>/newsfeed.aspx))
CSOM: CreatePost
JSOM: createPost
REST: POST <siteUri>/_api/social.feed/actor(item=@av)/feed/post/?@av='<teamSiteUri>/newsfeed.aspx' and pass the restCreationData parameter in the request body (specify null for the ID parameter)
SSOM: CreatePost
Publish a reply to a post
(specify the ID of the target thread)
CSOM: CreatePost
JSOM: createPost
REST: POST <siteUri>/_api/social.feed/Post/Reply and pass the restCreationData parameter in the request body
SSOM: CreatePost
Delete a post, reply, or thread in the current user's feed (deleting a root post deletes the whole thread) CSOM: DeletePost
JSOM: deletePost
REST: POST <siteUri>/_api/social.feed/Post/Delete and pass the ID parameter in the request body
SSOM: DeletePost
Get a thread (a root post and all its replies) from the user's feed CSOM: GetFullThread
JSOM: getFullThread
REST: POST <siteUri>/_api/social.feed/Post and pass the ID parameter in the request body
SSOM: GetFullThread
Have the user like (unlike) a post or reply CSOM: LikePost ( UnlikePost )
JSOM: likePost ( unlikePost)
REST: POST <siteUri>/_api/social.feed/Post/Like ( <siteUri>/_api/social.feed/Post/Unlike) and pass the ID parameter in the request body
SSOM: LikePost ( UnlikePost )
Get all likers for a post CSOM: GetAllLikers
JSOM: getAllLikers
REST: POST <siteUri>/_api/social.feed/Post/Likers and pass the ID parameter in the request body
SSOM: GetAllLikers
Get the posts that mention a user CSOM: GetMentions
JSOM: getMentions
REST: GET <siteUri>/_api/social.feed/my/MentionFeed
SSOM: GetMentions
Get the number of unread mentions for the current user CSOM: GetUnreadMentionCount
JSOM: getUnreadMentionCount
REST: GET <siteUri>/_api/social.feed/my/UnreadMentionCount
SSOM: GetUnreadMentionCount
Lock (unlock) a thread in the current user's feed CSOM: LockThread ( UnlockThread )
JSOM: lockThread ( unlockThread)
REST: POST <siteUri>/_api/social.feed/Post/Lock ( <siteUri>/_api/social.feed/Post/Unlock) and pass the ID parameter in the request body
SSOM: LockThread ( UnlockThread .md)

Note

The domain\user placeholder value in the REST example should be replaced with the account name of an actual user. To see how to pass a REST parameter in a request body, see the examples in the Social feed REST API reference.

SharePoint does not provide an API to customize the layout or rendering of microblog posts directly. SharePoint only provides the data and allows cross-platform and cross-device client applications to define layouts that are appropriate for their form factors and needs. In SharePoint development, you can use JavaScript overrides in client-side rendering, as described in Customize a list view in SharePoint Add-ins using client-side rendering.

Overview of feed types in the My Site Social API

Feed types represent slices of feed data. When you retrieve a feed for the current user, you can specify one of the following feed types:

  • Personal contains the posts and updates that are generated from a user. On My Site, this feed is shown on a user's About me page.

  • News contains the posts and updates that are generated from the current user and from the people and the content that the user is following. When you retrieve the News feed type, use the ByModifiedTime sort order option to get the most recent (cached) activities from the people who the user is following. On My Site, this feed is shown on a user's Newsfeed page.

  • Timeline contains the posts and updates that are generated from the current user and from the people and the content that the user is following. Timeline is particularly useful when you want feed data from a specific time range or when you want to sort with the ByCreatedTime option (which includes the largest sampling of people).

  • Likes contains reference threads with a PostReference property that represents a post that the current user has flagged with the Like attribute.

  • Everyone contains the threads from the current user's whole organization.

The server, client, and JavaScript object models provide the GetFeed method that you can use to retrieve any feed type for the current user and the GetFeedFor method that you can use to retrieve the Personal feed type (only) for a specified user. Both methods take a SocialFeedOptions object as a parameter, which you use to specify the time-based sort order, date range, and maximum number of threads to return.

Note

The REST service provides separate resources to retrieve each feed type, as shown in Table 2.

If a thread contains more than two replies, the server returns a digest of the thread that contains only the two most recent replies. (Thread digests have the IsDigest thread attribute applied.) If you want to get all the replies in a thread, call the GetFullThread method from the feed manager object and pass in the thread identifier.

See also