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.
- 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.
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
- 'use strict';
- var hostweburl;
- var appweburl;
- var followContentEndpoint;
- $(document).ready(function()
- {
- hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
- appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"))
-
- followContentEndpoint = decodeURIComponent(appweburl) + "/_api/social.following";
- getMyFollowedContent();
- $.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js");
- });
- function getQueryStringParameter(paramToRetrieve)
- {
- var params = document.URL.split("?")[1].split("&");
- for (var i = 0; i < params.length; i = i + 1)
- {
- var singleParam = params[i].split("=");
- if (singleParam[0] == paramToRetrieve) return singleParam[1];
- }
- }
- function getMyFollowedContent()
- {
- $.ajax({
- url: followContentEndpoint + "/my/followed(types=14)",
- headers: {
- "accept": "application/json;odata=verbose"
- },
- success: followedContentRetrieved,
- error: followContentErrorHandler
- });
- }
- function followedContentRetrieved(data)
- {
- var stringData = JSON.stringify(data);
- var jsonObject = JSON.parse(stringData);
- var types = {
- 1: "document",
- 2: "site",
- 3: "tag"
- };
- var followedActors = jsonObject.d.Followed.results;
- var followedList = "You're Following the below contents:";
- for (var i = 0; i < followedActors.length; i++) {
- var actor = followedActors[i];
- followedList += "<p>" + types[actor.ActorType] + ": \"" + actor.Name + "\"</p>";
- }
- $("#fldCntResult").html(followedList);
- }
- function followContentErrorHandler(data, errorcode, errormessage)
- {
- alert("Couldn't generate the Count" + errormessage);
- }
Step 4
Publish the solution and click the Trust It Button.
Output