Th example in this article shows how to retrieve My Feeds in SharePoint using the REST API. Develop the project using the following method in the NAPA Tool.
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 Create Site and then choose the Create button.
- Replace APP.js with the following source code below.
- Publish Your App.
Prerequisites
The following is the important procedure to be done before creating the app.
Specify the permissions that your app needs as in the following.
Choose the Properties button at the bottom of the page.
- In the Properties window, choose Permissions.
- In the Content category, set the Write permissions for the Tenant scope.
- In the Social category, set the Read permissions for the User Profiles scope.
- Close the Properties window.
Endpoint URI
http://<siteCollection>/<site>/_api/social.feed/my
Test the URI In Browser
Source Code
- 'use strict';
-
- var hostweburl;
- var appweburl;
- var feedManagerEndpoint;
-
-
-
- $(document).ready(function () {
-
-
- hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
- appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
- feedManagerEndpoint = decodeURIComponent(appweburl)+ "/_api/social.feed";
- getMyFeed();
- });
-
-
- function getMyFeed() {
- $.ajax( {
-
- url: feedManagerEndpoint + "/my/Feed",
- headers: {
- "accept": "application/json;odata=verbose"
- },
- success: feedRetrieved,
- error: function (xhr, ajaxOptions, thrownError) {
- alert("GET error:\n" + xhr.status + "\n" + thrownError);
- }
- });
- }
-
-
- function feedRetrieved(data) {
- var stringData = JSON.stringify(data);
- var jsonObject = JSON.parse(stringData);
-
- var feed = jsonObject.d.SocialFeed.Threads;
- var threads = feed.results;
- var feedContent = "";
- for (var i = 0; i < threads.length; i++) {
- var thread = threads[i];
- var participants = thread.Actors;
- var owner = participants.results[thread.OwnerIndex].Name;
- feedContent += '<p>' + owner +
- ' said "' + thread.RootPost.Text + '"</p>';
- }
- $("#message").html(feedContent);
- }
-
-
- 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
Publish the app and click the Trust it Button.
Output
My Feeds are retrieved successfully.
Newsfeed in SharePoint Page: