We can use the SharePoint 2013 Representational State Transfer (REST) service to do the same tasks you can do when you use the .NetCSOM, JSOM.
Here I explain how to retrieve the site name and URL followed by the current user in SharePoint 2013 using a client object model (REST API and JavaScript) and displaying it in the SharePoint page.
1. Create a new page and a Content Editor Webpart (CEWP).
2. Edit the web part that was added to the page.
3. Upload your text file script into the site assests and copy the path of the text file and paste it into the Content link in CEWP.
4. Output
Code
The following example shows how to retrieve all of the following sites:
- <html>
- <head>
- <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
- <script type="text/javascript">
- var followingManagerEndpoint;
- var followedCount;
- var followingEndpoint;
- var URL;
- var website;
- var clientContext;
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', loadWebsite);
- function loadWebsite() {
- clientContext = SP.ClientContext.get_current();
- website = clientContext.get_web();
- clientContext.load(website);
- clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
- }
- function onRequestSucceeded() {
- URL = website.get_url();
- followingManagerEndpoint = decodeURIComponent(URL) + "/_api/social.following";
- getMyFollowedContent();
- }
- function onRequestFailed(sender, args) {
- alert('Error: ' + args.get_message());
- }
- // Get the content that the current user is following.
- // The "types=14" parameter specifies all content types
- // (documents = 2 + sites = 4 + tags = 8).
- function getMyFollowedContent() {
- $.ajax( {
- url: followingManagerEndpoint + "/my/followed(types=14)",
- headers: {
- "accept": "application/json;odata=verbose"
- },
- success: followedContentRetrieved,
- error: requestFailed
- });
- }
- // Parse the JSON data and iterate through the collection.
- 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 items:";
- for (var i = 0; i < followedActors.length; i++) {
- var actor = followedActors[i];
- followedList += "<p>The " + types[actor.ActorType] + ": \"" +actor.Name + "\"</p>"+"<p>Site URL " + ": \"" +
- actor.Uri+ "\"</p>";;
- }
- $("#Follow").html(followedList);
- }
- function requestFailed(xhr, ajaxOptions, thrownError) {
- alert('Error:\n' + xhr.status + '\n' + thrownError + '\n' + xhr.responseText);
- }
- </script>
- </head>
- <body>
- <div id="Follow"></div>
- </body>
- </html>

CesPosted Jun 16, 2021, 3:59 PM
Does this work in SP modern? I tried but nothing showed.
Yash patelPosted Dec 20, 2018, 7:22 AM
I want only followed site collection(not followed subsites) using followed rest api Is there any solution for this?/
B MPosted Jul 26, 2016, 9:22 AM
Is it possible to create a link to each of the returned sites using this method?
Gowtham RajamanickamPosted Apr 26, 2016, 9:08 AM
thank u so much
Gowtham RajamanickamPosted Apr 26, 2016, 9:08 AM
thank u so much
Gowtham RajamanickamPosted Apr 26, 2016, 9:08 AM
thank u so much
Gowtham RajamanickamPosted Apr 26, 2016, 9:08 AM
thank u so much
Gowtham RajamanickamPosted Apr 26, 2016, 9:08 AM
thank u so much
Gowtham RajamanickamPosted Apr 26, 2016, 9:08 AM
thank u so much
Gowtham RajamanickamPosted Apr 26, 2016, 9:07 AM
thank u all
Sr KarthigaPosted Apr 26, 2016, 9:01 AM
good one sir
Gowtham RajamanickamPosted Apr 6, 2015, 4:08 AM
thank u all
Gowtham RajamanickamPosted Apr 6, 2015, 4:08 AM
thank u vijay s
Vijay SPosted Apr 6, 2015, 3:06 AM
Good Article
Gowtham RajamanickamPosted Mar 16, 2015, 9:09 AM
thank u...
Gowtham RajamanickamPosted Mar 16, 2015, 9:09 AM
thank u...
Gowtham RajamanickamPosted Mar 16, 2015, 9:09 AM
Thank u..
BK GPosted Mar 6, 2015, 9:01 PM
good one....
Prasham SabadraPosted Mar 3, 2015, 7:11 PM
Nice Article. Thanks for sharing!