How to Retrieve My Feeds in SharePoint Using REST API

Th example in this article shows how to retrieve My Feeds in SharePoint using the REST API. Develop the project using the following method in the NAPA Tool.

On your Developer Site, open the "Napa" Office 365 Development Tools and then choose Add New Project.

  • Choose the App for SharePoint template, name the project Create Site and then choose the Create button.
  • Replace APP.js with the following source code below.
  • Publish Your App.

Prerequisites

The following is the important procedure to be done before creating the app.

Specify the permissions that your app needs as in the following.

Choose the Properties button at the bottom of the page.

  • In the Properties window, choose Permissions.
  • In the Content category, set the Write permissions for the Tenant scope.
  • In the Social category, set the Read permissions for the User Profiles scope.
  • Close the Properties window.

Endpoint URI

http://<siteCollection>/<site>/_api/social.feed/my

Test the URI In Browser



Source Code

  1. 'use strict';  
  2.    
  3. var hostweburl;  
  4. var appweburl;  
  5. var feedManagerEndpoint;  
  6.    
  7.  // Get the URLs for the app web the host web URL from the query string.  
  8.   
  9. $(document).ready(function () {  
  10.    
  11.     //Get the URI decoded URLs.  
  12.     hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));  
  13.     appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));  
  14.  feedManagerEndpoint = decodeURIComponent(appweburl)+ "/_api/social.feed";  
  15. getMyFeed();  
  16. });  
  17.    
  18.    
  19. function getMyFeed() {  
  20.     $.ajax( {  
  21.           
  22.   url: feedManagerEndpoint + "/my/Feed",  
  23.         headers: {   
  24.             "accept""application/json;odata=verbose"  
  25.         },  
  26.         success: feedRetrieved,  
  27.         error: function (xhr, ajaxOptions, thrownError) {   
  28.             alert("GET error:\n" + xhr.status + "\n" + thrownError);  
  29.         }  
  30.     });      
  31. }  
  32.   
  33. // Parse the JSON data and iterate through the feed.  
  34. function feedRetrieved(data) {  
  35.     var stringData = JSON.stringify(data);  
  36.     var jsonObject = JSON.parse(stringData);   
  37.    
  38.     var feed = jsonObject.d.SocialFeed.Threads;   
  39.     var threads = feed.results;  
  40.     var feedContent = "";  
  41.     for (var i = 0; i < threads.length; i++) {  
  42.         var thread = threads[i];  
  43.         var participants = thread.Actors;  
  44.         var owner = participants.results[thread.OwnerIndex].Name;  
  45.         feedContent += '<p>' + owner +   
  46.             ' said "' + thread.RootPost.Text + '"</p>';  
  47.     }    
  48.     $("#message").html(feedContent);   
  49. }  
  50. // Retrieve a query string value.  
  51. // For production purposes you may want to use a library to handle the query string.  
  52. function getQueryStringParameter(paramToRetrieve) {  
  53.     var params = document.URL.split("?")[1].split("&");  
  54.     for (var i = 0; i < params.length; i = i + 1) {  
  55.     var singleParam = params[i].split("=");  
  56.     if (singleParam[0] == paramToRetrieve) return singleParam[1];  
  57.   }  
  58. }  
Publish

Publish the app and click the Trust it Button.


Output

My Feeds are retrieved successfully.

Newsfeed in SharePoint Page: