sharepoint - Sharepoint 在线:以编程方式发布到新闻源
问题描述
我想创建一个可以将数据发布到特定 Sharepoint 新闻提要的 Web 部件,但一直无法找到任何好的文档。我找到的唯一链接是: https ://msdn.microsoft.com/library/e9ad06a1-831d-8ed0-c76e-8b049f14216f%28Office.15%29.aspx
我的问题是:我可以使用什么方法将数据发布到 Sharepoint 站点的新闻提要?
他们在链接中提到您可以发布到“站点提要的 URL”。这和新闻提要一样吗?有人做过类似的事情吗?
解决方案
我们可以使用 JSOM 或 REST API 来实现它。
REST 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>
参考:
推荐阅读
- java - 无法解决 gradle 中的融合 kafka 依赖项?
- python - 为什么两个代码看起来一样,但一个不起作用?Python链表数据结构2
- java - 按下对话框的按钮时打开另一个活动?
- jenkins - Ansible playbook 当条件访问其他 playbook 但状态正在跳过时
- security - Owncloud:登录尝试的日志文件
- crystal-lang - 如何获取一个类的所有属性
- angular - mat-sidenav 列不起作用,fxLayout="column"
- c++ - 如何通过 C++ 中的函数参数传递固定大小的初始值设定项列表的初始值设定项列表?
- python - 有什么方法可以像 js 中的 es6 那样在 python 中解构 dict?
- python - Missing values replaced with average of its neighbors (timeseries)