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.
Step 2Change the permission as in the following:
- Tenant = Write
- User Profiles = Read
Step 3Update the Default.aspx and App.js files.Default ASPXApp.js
- 'use strict';
- var hostweburl;
- var appweburl;
- var followCountEndpoint;
- var followCount;
-
- $(document).ready(function(){
- hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
- appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"))
-
- followCountEndpoint = decodeURIComponent(appweburl) + "/_api/social.following";
- followedCount();
-
- $.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 followedCount() {
- $.ajax( {
- url: followCountEndpoint + "/my/followedcount(types=14)",
- headers: {
- "accept": "application/json;odata=verbose"
- },
- success: followCountSuccessHandler,
- error: followCountErrorHandler
- } );
- }
-
- function followCountSuccessHandler(data)
- {
- followCount = data.d.FollowedCount;
- var followCountResult = "You're currently following " +followCount+" Items";
- document.getElementById("FlwCountResult").innerHTML = followCountResult;
- }
-
- function followCountErrorHandler(data,errorcode,errormessage)
- {
- alert("Couldn't generate the Count" + errormessage);
- }
Step 4Publish the solution and click the Trust It Button.
Output