我需要从 SharePoint Online 网站下载用户的个人资料图像,然后将该图像插入 PPT。为此,我使用下面的 C# 代码:
string userPhotoURL = "https://microsoft.sharepoint.com/_layouts/15/userphoto.aspx?size=M&username=username@microsoft.com";
using (var client = new WebClient())
{
client.Headers.Add("User-Agent: Other");
client.Credentials = Utility.GetSharePointOnlineCredentials(); // includes username and SecureString password
client.DownloadFile(userPhotoURL, "D:\sample.jpg");
}
// More code to read the D:\sample.jpg and insert it into PPT
但是,上面返回 403 响应。
注意:我需要从服务器端实现这一点。