Introduction
This is developed using the NAPA development tool, you can just pass the Document URL in the Text box, on the click of the “Stop Follow” button the Result will be displayed in an alert message.
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: Tenant = Write, User Profiles = Read

Step 3
Update Default.aspx and App.js file.
Default ASPX

App.js
- 'use strict';
- var hostweburl;
- var appweburl;
- var documenturl;
- var followDocEndpoint;
- $(document).ready(function()
- {
- hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
- appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"))
- followDocEndpoint = decodeURIComponent(appweburl) + "/_api/social.following";
- $("#btnclick").click(function(event)
- {
- documenturl = document.getElementById("stopFollow").value;
- stopFollow();
- event.preventDefault();
- });
- $.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js");
- });
- function stopFollow()
- {
- $.ajax({
- url: followDocEndpoint + "/stopfollowing",
- type: "POST",
- data: JSON.stringify({
- "actor": {
- "__metadata":
- {
- "type": "SP.Social.SocialActorInfo"
- },
- "ActorType": 1,
- "ContentUri": documenturl,
- "Id": null
- }
- }),
- headers:
- {
- "accept": "application/json;odata=verbose",
- "content-type": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val()
- },
- success: function()
- {
- alert('The user has stopped following the document.');
- },
- error: stopFollowErrorHandler
- });
- }
- function stopFollowErrorHandler(data, errorcode, errormessage)
- {
- alert("Couldn't stop following the document" + errormessage);
- }
- 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];
- }
- }
Publish the solution and click the Trust It button.

Step 5
Enter the Document URL and click on the Stop Follow button.

Output


Karthik Muthu KaruppanPosted Mar 27, 2015, 11:54 AM
good work....
Vijay SPosted Mar 27, 2015, 2:25 AM
Thank you Gowtham Rajamanickam
Gowtham RajamanickamPosted Mar 26, 2015, 10:13 PM
really great work vijay.....beginners and experienced can understand easily.....