Introduction

This article helps to retrieve the followed content 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.

Step 2

Change the Permission as in the following:

Tenant = Write

User Profiles = Read



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 followContentEndpoint;
  5. $(document).ready(function()
  6. {
  7. hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
  8. appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"))
  9. followContentEndpoint = decodeURIComponent(appweburl) + "/_api/social.following";
  10. getMyFollowedContent();
  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 getMyFollowedContent()
  23. {
  24. $.ajax({
  25. url: followContentEndpoint + "/my/followed(types=14)",
  26. headers: {
  27. "accept": "application/json;odata=verbose"
  28. },
  29. success: followedContentRetrieved,
  30. error: followContentErrorHandler
  31. });
  32. }
  33. function followedContentRetrieved(data)
  34. {
  35. var stringData = JSON.stringify(data);
  36. var jsonObject = JSON.parse(stringData);
  37. var types = {
  38. 1: "document",
  39. 2: "site",
  40. 3: "tag"
  41. };
  42. var followedActors = jsonObject.d.Followed.results;
  43. var followedList = "You're Following the below contents:";
  44. for (var i = 0; i < followedActors.length; i++) {
  45. var actor = followedActors[i];
  46. followedList += "<p>" + types[actor.ActorType] + ": \"" + actor.Name + "\"</p>";
  47. }
  48. $("#fldCntResult").html(followedList);
  49. }
  50. function followContentErrorHandler(data, errorcode, errormessage)
  51. {
  52. alert("Couldn't generate the Count" + errormessage);
  53. }

Step 4

Publish the solution and click the Trust It Button.



Output