Introduction

This article helps to retrieve all the users following the current user 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.

Step 2

Change the permission:

Step 3

Update the Default.aspx and App.js files

Default ASPX



App.js

  1. 'use strict';
  2. var hostweburl;
  3. var appweburl;
  4. var myFollowerEndpoint;
  5. var followers;
  6. $(document).ready(function(){
  7. hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
  8. appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"))
  9. myFollowerEndpoint = decodeURIComponent(appweburl) + "/_api/social.following";
  10. getMyFollowers();
  11. });
  12. function getQueryStringParameter(paramToRetrieve)
  13. {
  14. var params = document.URL.split("?")[1].split("&");
  15. for (var i=0; i<params.length; i= i + 1)
  16. {
  17. var singleParam = params[i].split("=");
  18. if(singleParam[0] == paramToRetrieve) return singleParam[1];
  19. }
  20. }
  21. function getMyFollowers() {
  22. $.ajax( {
  23. url: myFollowerEndpoint + "/my/followers",
  24. headers: {
  25. "accept": "application/json;odata=verbose"
  26. },
  27. success: myFollowersSuccessHandler,
  28. error: myFollowersErrorHandler
  29. });
  30. }
  31. function myFollowersSuccessHandler(data)
  32. {
  33. var stringData = JSON.stringify(data);
  34. var jsonObject = JSON.parse(stringData);
  35. var folResult = jsonObject.d.Followers.results;
  36. followers = "<p>The Person who follows you are:</p>";
  37. for (var i=0; i<folResult.length; i++)
  38. {
  39. followers+= "<P>"+folResult[i].Name+"</p>";
  40. }
  41. document.getElementById("myFollowersResult").innerHTML = followers;
  42. }
  43. function myFollowersErrorHandler(data,errorcode,errormessage)
  44. {
  45. alert("Couldn't get the followers " + errormessage);
  46. }
Step 4

Publish the solution and click the Trust It Button.

Output