Sharepoint 在线:以编程方式 post 到新闻提要

Sharepoint online: Programmatically post to news feed

我想创建一个 Web 部件,它可以 post 数据到特定 Sharepoint 的新闻提要,但找不到任何好的文档。我发现的唯一 link 是: https://msdn.microsoft.com/library/e9ad06a1-831d-8ed0-c76e-8b049f14216f%28Office.15%29.aspx

我的问题是:我可以使用什么方法将数据post发送到 Sharepoint 站点的新闻提要?

在 link 中,他们提到您可以 post 到 "the URL of a site feed"。这和新闻提要一样吗?有人做过类似的事情吗?

我们可以使用JSOM或者RESTAPI来实现。

休息 API:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(function(){   
    $.ajax( {
        url: weburl + "/_api/social.feed/my/Feed/Post",
        type: "POST",
        data: JSON.stringify({ 
            'restCreationData':{
                '__metadata':{ 
                    'type':'SP.Social.SocialRestPostCreationData'
                },
                'ID': null, 
                'creationData':{ 
                    '__metadata':{ 
                        'type':'SP.Social.SocialPostCreationData'
                    },
                    'ContentText': "the post content text",
                    'UpdateStatusText':false
                } 
            } 
        }),
        headers: { 
            "accept": "application/json;odata=verbose",
            "content-type":"application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function(){
            console.log("success to post ");
        },
        error: function (xhr, ajaxOptions, thrownError) { 
            alert("POST error:\n" + xhr.status + "\n" + thrownError);
        }
    });
});
</script>

JSOM:

<script type="text/javascript" src="/_layouts/15/sp.userprofiles.js"></script>
<script type="text/javascript">
SP.SOD.executeOrDelayUntilScriptLoaded(WritePost, 'SP.UserProfiles.js');
function WritePost() {
    var oclientContext;
    var ofeedManager;
    var oresultThread;

    // Initialize the current client context and the SocialFeedManager instance.
    oclientContext = SP.ClientContext.get_current();
    ofeedManager = new SP.Social.SocialFeedManager(oclientContext);

    // Add a link to be included in the post.
    var olinkDataItem = new SP.Social.SocialDataItem();
    olinkDataItem.set_itemType(SP.Social.SocialDataItemType.link);
    olinkDataItem.set_text('My blog url');
    olinkDataItem.set_uri('http://sundarnarasiman.net');
    var osocialDataItems = [ olinkDataItem ];

    // Set up the post content
    var opostCreationData = new SP.Social.SocialPostCreationData();
    opostCreationData.set_contentText('The text for the post, which contains a {0}.');
    opostCreationData.set_contentItems(osocialDataItems);

    // Write the post
    oresultThread = ofeedManager.createPost(null, opostCreationData);
    oclientContext.executeQueryAsync(WriteSucceeded, WriteFailed);
}

function WriteSucceeded(sender, args) {
    //$get("ResultMessage").innerText = 'Successfully posted the message to Posts';
}
function WriteFailed(sender, args) {
    //$get("ResultMessage").innerText = 'Failure in writing message' + args.get_message();
}
</script>

参考:

Post/Reply a post by Social feed REST API in SharePoint 2013

How to publish a post to SharePoint Social Feed using SharePoint 2013 JSOM