[英]Sharepoint authentication using javascript Rest api or jquery
我只是通过使用javascript开发移动共享应用程序,但是不知道如何开始。 javascript(jquery)中是否有任何api用于在sharepoint中进行身份验证并获取用户详细信息。
提前致谢。
要在SharePoint 2013和Online中开发Web应用程序,您有2个主要选项可用于从列表,库或用户详细信息中查询数据,即客户端对象模型和SharePoint REST API。
这是使用Client对象模型更新列表数据的示例
ClientContext context = new ClientContext("http://SiteUrl");
List announcementsList = context.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem["Title"] = "My New Item!";
newItem["Body"] = "Hello World!";
newItem.Update();
context.ExecuteQuery();
首选的另一种选择是使用REST API查询端点。 您可以在SharePoint中查询许多API,最有用的是Search API或Social API,User Profile API等。
这是示例示例,您可以查询该示例以检索JSON数据,可以将其放在浏览器中或发布到url以查看返回的内容。
http://<siteCollection>/<site>/_api/social.feed/my/feed/post
这是在SharePoint中获取当前用户的用户配置文件数据的示例
$(document).ready(function(){
// Ensure the SP.UserProfiles.js file is loaded
SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');
});
var userProfileProperties;
function loadUserData(){
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
//Get properties of the current user
userProfileProperties = peopleManager.getMyProperties()
clientContext.load(userProfileProperties);
clientContext.executeQueryAsync(onSuccess, onFail);
}
function onSuccess() {
console.log(userProfileProperties.get_displayName());
}
function onFail(sender, args) {
console.log("Error: " + args.get_message());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.