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.

application build

Step 2

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

Publish the solution and click the Trust It Button.

followed count

Output

followed count share point