码迷,mamicode.com
首页 > 其他好文 > 详细

Custom Social Newsfeed in SharePoint 2013

时间:2015-01-26 19:25:27      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

Requirement

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.

Introduce:

1. Retrieve all post posted myself, the data is from the default newsfeed

技术分享

and the below is the default newsfeed:

技术分享

2. New a post and retrieve the hastag

技术分享

3. Reply a post

技术分享

4. Like and Unlike the post

技术分享

3. Implement in detail

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

Retrieve all newsfeed posted by myself

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);
        }
    });
}

New a post

// 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 a post

//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/Unlike apost

// 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);
        }
    });
}


Retirve hastags auto in UI

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


More:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!