Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SharePoint REST显示当前用户配置文件图片_Sharepoint_Sharepoint 2013_Office365_Office365 Apps_Office365 Restapi - Fatal编程技术网

SharePoint REST显示当前用户配置文件图片

SharePoint REST显示当前用户配置文件图片,sharepoint,sharepoint-2013,office365,office365-apps,office365-restapi,Sharepoint,Sharepoint 2013,Office365,Office365 Apps,Office365 Restapi,通过REST从当前用户的配置文件获取URL时,在更新src时,图像标记无法显示: <img id="escMyPic" src="" alt="" /> <script type="text/javascript"> $.ajax({ url: strURL + "/_api/sp.userprofiles.peoplemanager/getmyproperties", type: "GET", headers: { "accep

通过REST从当前用户的配置文件获取URL时,在更新src时,图像标记无法显示:

<img id="escMyPic" src="" alt="" />

<script type="text/javascript">
$.ajax({
    url: strURL + "/_api/sp.userprofiles.peoplemanager/getmyproperties",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: MyPictureSucceeded,
    error: MyPictureFailed
});
function MyPictureSucceeded(data) {
    if(data.d.PictureUrl != null) {
        $('#escMyPic').attr('src', data.d.PictureUrl);
    }
}
function MyPictureFailed() {
        alert('Error: Unexpected error loading profile picture.');
}
</script>

$.ajax({
url:strURL+“/\u api/sp.userprofiles.peoplemanager/getmyproperties”,
键入:“获取”,
标题:{
“接受”:“application/json;odata=verbose”,
},
成功:我的照片成功了,
错误:MyPictureFailed
});
函数MyPictureSucceeded(数据){
如果(data.d.PictureUrl!=null){
$('escMyPic').attr('src',data.d.PictureUrl);
}
}
函数MyPictureFailed(){
警报('错误:加载配置文件图片时发生意外错误');
}
在SharePoint Online中,返回的url如下所示:

它重定向到:

使用浏览器开发工具,可以看到返回的mime类型不是image/jpg,而是text/plain。我删除了查询字符串参数,甚至将硬编码的URL放在图像标记src中,但它就是不显示。开发工具中的响应主体也是空白的。在显示之前,它似乎正在重定向和验证

在浏览器地址栏中放置硬编码URL时,图片显示良好,dev tools响应头将图片显示为URL的内容,MIME类型为image/jpg


如何从REST调用中获得要显示的配置文件图像?

除了返回
PersonalUrl
属性的
/\u api/sp.userprofiles.peoplemanager/getmyproperties
端点之外,还可以通过
\u layouts/15/userphoto.aspx?size=&accountname=
页面请求用户配置文件图片,其中

  • size
    -可设置为
    S/M/L
    ,表示小型/中型/大型 图像大小
  • accountname
    -用户帐户名
示例

var url = getMyPictureUrl(_spPageContextInfo.webAbsoluteUrl,_spPageContextInfo.userLoginName,"M");
$('#escMyPic').attr('src', url);
在哪里


这里的帐户名是什么?是电子邮件地址吗?或者
i:0#.f |会员资格|电子邮件地址
格式?因为每次我得到默认图像。另外,我正在尝试获取其他用户的配置文件映像,而不是当前登录的用户。第二个,需要在声明格式中提供
accountName
,使用“siteAbsoluteUrl”而不是“webAbsoluteUrl”。
function getMyPictureUrl(webUrl,accountName,size){
    return webUrl + "/_layouts/15/userphoto.aspx?size=" + size + "&accountname=" + accountName;
}