8

SharePoint JavaScript 获取User Profile文件

 3 years ago
source link: https://www.cnblogs.com/jianyus/p/14267456.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

SharePoint JavaScript 获取User Profile文件

  前言

  最近,需要获取SharePoint 用户相关的内容,然后,就找到了一段脚本。

  正文

  请求的AJAX方法,如下图:

var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
var accountName = "i:0#.f|membership|" + _spPageContextInfo.userLoginName;
var xhr = new XMLHttpRequest();
xhr.open('GET', siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'", true);
xhr.setRequestHeader("Accept", "application/json; odata=verbose");
xhr.onreadystatechange = function() {
    // readyState == 4说明请求已完成
    if (xhr.readyState == 4 && xhr.status == 200 || xhr.status == 304) {
        // 从服务器获得数据 
        console.log(JSON.parse(xhr.responseText).d);
    }
};
xhr.send();

  AJAX返回的数据,JSON格式化一下,就可以使用相关的属性了。

256729-20210213125219244-77143748.png

  结束语

  这里可以获取用户香瓜的信息,不过很多信息需要提前配置好,比如DirectReports等。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK