Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE.eu :: How to Retrieve Followed Sites in SharePoint 2013 Using REST API ?
In this post, let me tell you about How to Retrieve Followed Sites in SharePoint 2013 Using REST API. We can use the SharePoint 2013 representational State Transfer (REST) service to try to to constant tasks you’ll be able to do when you use the .NetCSOM, JSOM.
Here I make a case for a way 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. Make a new page and a Content Editor Webpart (CEWP)
2. And now, edit the web part that was added to the page as shown on the below picture:
3. And then , upload your text file script into the site assests & copy the path of the text file and paste it into the Content link in CEWP.
Write the following code shows how to retrieve all of the following sites:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<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> |
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options
Print article | This entry was posted by Peter on April 22, 2015 at 4:03 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |