【问题标题】:Sharepoint authentication using javascript Rest api or jquery使用 javascript Rest api 或 jquery 的 Sharepoint 身份验证
【发布时间】:2014-10-18 07:13:40
【问题描述】:

我只是使用 javascript 在移动设备上开发一个共享点应用程序,但不知道如何开始。 javascript(jquery) 中是否有任何 api 用于在 sharepoint 中进行身份验证并获取用户详细信息。

提前致谢。

【问题讨论】:

  • 你在这个线程上有任何解决方案..
  • 您找到解决方案了吗?如果是,请分享

标签: javascript jquery web-services sharepoint sharepoint-api


【解决方案1】:

对于在 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());
}

【讨论】:

  • 感谢分享知识。但我想从共享点对用户进行身份验证并获取用户详细信息
  • @PraveenKumar 如果您找到解决方案,请与我们分享。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-05
  • 2015-03-29
  • 2018-07-26
相关资源
最近更新 更多