标签:
Implement a custom social newsfeed, user can retrieve/new/reply/like/unlike a post, and ability to auto retrieve hastags when input "#". you would be notice that the UI is same as the default Newsfeed in SharePoint 2013. Correct! I re-built the feature follow up the default newsfeed.
and the below is the default newsfeed:
Preparation: Make sure built my site, you can check the url: http://siteurl/my/default.aspx.
Post/Reply a post by Social feed REST API in SharePoint 2013 in detali
var appweburl = <a target=_blank href="http://weburl">http://weburl</a>; feedManagerEndpoint = decodeURIComponent(appweburl) + "/_api/social.feed"; 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); } }); }
// Publish a post to the current user's feed function postToMyFeed(posttext) { $.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': posttext, 'UpdateStatusText': false } } }), headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() }, success: function (data) { // }, error: function (xhr, ajaxOptions, thrownError) { alert("POST error:\n" + xhr.status + "\n" + thrownError); } }); }
//reply post function Reply($object, postid, contenttext) { $.ajax({ url: feedManagerEndpoint + "/post/reply", type: "POST", data: JSON.stringify({ 'restCreationData': { '__metadata': { 'type': 'SP.Social.SocialRestPostCreationData' }, 'ID': postid, 'creationData': { '__metadata': { 'type': 'SP.Social.SocialPostCreationData' }, 'ContentText': contenttext, 'UpdateStatusText': false } } }), headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() }, success: function (data) { // }, error: function (xhr, ajaxOptions, thrownError) { alert("POST error:\n" + xhr.status + "\n" + thrownError); } }); }
// like a post via id function LikePostByID($object, postid) { $.ajax({ url: feedManagerEndpoint + "/post/like", type: "POST", data: JSON.stringify({ 'ID': postid }), headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() }, success: function (data) { console.log("success to like"); }, error: function (xhr, ajaxOptions, thrownError) { alert("POST error:\n" + xhr.status + "\n" + thrownError); } }); } // unlike a post via id function UnLikePostByID($object, postid) { $.ajax({ url: feedManagerEndpoint + "/post/unlike", type: "POST", data: JSON.stringify({ 'ID': postid }), headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() }, success: function (data) { console.log("success to unlike"); }, error: function (xhr, ajaxOptions, thrownError) { alert("POST error:\n" + xhr.status + "\n" + thrownError); } }); }
please refer to Autocomplete(Enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering.)
and Sharepoint 2013 Retrieve Taxonomy Term Store via Javascript
Social feed REST API reference for SharePoint 2013 in detail, and if you want the project code, please email to me.
Custom Social Newsfeed in SharePoint 2013
标签:
原文地址:http://blog.csdn.net/tristan_dong/article/details/43153975