Custom Social Newsfeed in SharePoint 2013

6 篇文章 0 订阅
2 篇文章 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.


















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值