REST API POST and GET Error

Mar 10 2015 8:40 AM
i have used below code to retrive the newsfeeds but im getting 403 error.i think url formation for POST and GET is wrong.Kindly anyone worked help mee. 
 
var feedManagerEndpoint;
// Get the SPAppWebUrl parameter from the query string and build
// the feed manager endpoint.
$(document).ready(function () {
var appweburl;
var params = document.URL.split("?")[1].split("&");
for (var i = 0; i < params.length; i = i + 1) {
var param = params[i].split("=");
if (param[0] === "SPAppWebUrl") appweburl = param[1];
}
alert(appweburl);
feedManagerEndpoint = decodeURIComponent(appweburl)+ "/_api/social.feed";
alert(feedManagerEndpoint);
postToMyFeed();
});
// Publish a post to the current user's feed by using the
// "<app web URL>/_api/social.feed/my/Feed/Post" endpoint.
function postToMyFeed() {
alert('pOST');
$.ajax( {
url: feedManagerEndpoint+"/my/Feed/Post",
type: "POST",
data: JSON.stringify( {
'restCreationData':{
'__metadata':{
'type':'SP.Social.SocialRestPostCreationData'
},
'ID':null,
'creationData':{
'__metadata':{
'type':'SP.Social.SocialPostCreationData'
},
'ContentText':'This post was published using REST.',
'UpdateStatusText':false
}
}
}),
headers: {
"accept": "application/json;odata=verbose",
"content-type":"application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: getMyFeed,
error: function (xhr, ajaxOptions, thrownError) {
alert("POST error:\n" + xhr.status + "\n" + thrownError);
}
});
}
// Get the current user's feed by using the
// "<app web URL>/_api/social.feed/my/Feed" endpoint.
function getMyFeed() {
alert('get');
$.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);
}
});
}
// Parse the JSON data and iterate through the feed.
function feedRetrieved(data) {
var stringData = JSON.stringify(data);
var jsonObject = JSON.parse(stringData);
alert(jsonObject);
var feed = jsonObject.d.SocialFeed.Threads;
alert(feed.results);
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);
}

Answers (1)