Retrieve Count of Followed Contents From SharePoint 2013 Using REST

Introduction

This article helps the retrieval of the count of the followed contents from MySite using REST in SharePoint 2013. This is developed using the NAPA development tool.

Step 1

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 and then click the Create button. 
  • Replace Default.aspx with the following code.
  • Replace APP.js with the following source code. 
  • Publish Your App.
application build

Step 2

Change the permission as in the following:
  • Tenant = Write 

  • User Profiles = Read
office 365

Step 3

Update the Default.aspx and App.js files.

Default ASPX

default asp page

App.js
  1. 'use strict';  
  2. var hostweburl;  
  3. var appweburl;  
  4. var followCountEndpoint;  
  5. var followCount;  
  6.   
  7. $(document).ready(function(){  
  8.     hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));  
  9.     appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"))  
  10.       
  11.     followCountEndpoint = decodeURIComponent(appweburl) + "/_api/social.following";  
  12.     followedCount();  
  13.       
  14.     $.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js");  
  15. });  
  16.   
  17.   
  18. function getQueryStringParameter(paramToRetrieve)  
  19. {  
  20.     var params = document.URL.split("?")[1].split("&");  
  21.     for (var i=0; i<params.length; i= i + 1)  
  22.     {  
  23.         var singleParam = params[i].split("=");  
  24.         if(singleParam[0] == paramToRetrieve) return singleParam[1];          
  25.     }  
  26. }  
  27.   
  28.   
  29. function followedCount() {  
  30.     $.ajax( {  
  31.         url: followCountEndpoint + "/my/followedcount(types=14)",  
  32.         headers: {   
  33.             "accept""application/json;odata=verbose"  
  34.         },  
  35.         success: followCountSuccessHandler,  
  36.         error: followCountErrorHandler  
  37.     } );  
  38. }  
  39.   
  40. function followCountSuccessHandler(data)  
  41. {  
  42.     followCount = data.d.FollowedCount;  
  43.     var followCountResult = "You're currently following " +followCount+" Items";  
  44.     document.getElementById("FlwCountResult").innerHTML = followCountResult;  
  45. }  
  46.   
  47. function followCountErrorHandler(data,errorcode,errormessage)  
  48. {  
  49.     alert("Couldn't generate the Count" + errormessage);  
  50. }  
Step 4

Publish the solution and click the Trust It Button.

followed count

Output

followed count share point

Up Next
    Ebook Download
    View all
    Learn
    View all