我正在使用javascript在移动设备上开发一个sharepoint应用程序,但不知道如何开始。 javascript(jquery) 中是否有任何 api 可以在 sharepoint 中进行身份验证并获取用户详细信息。
提前致谢。
最佳答案
要在 SharePoint 2013 和 Online 中开发 Web 应用程序,您有 2 个主要选项可用于从列表、库或用户详细信息查询数据:客户端对象模型和 SharePoint REST API。
以下是使用 Client object model 更新列表数据的示例
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或社交 API、用户个人资料 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());
}
关于javascript - 使用 javascript Rest api 或 jquery 进行 Sharepoint 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26437261/