从 SharePoint 在线下载特定用户的文件

Download certain user's files from SharePoint online

我公司有像\<company>.sharepoint.com这样的商业账户和域名 所以每个员工都有自己的 OneDrive space 喜欢 \<company>-my.sharepoint.com 我们有专门的帐户来管理我们存储在它自己的 onedrive 上的文件,就像这样 files stored on emploee onedrive

我尝试了 SharePoint CSOM、Microsoft Graph API 和 SharePointAPI。使用其中任何一个我都可以获得与文件相关的数据,如名称、上次更改日期等。 但是当我尝试使用这样的方式下载它时:

var file = clientContext.Web.GetFileByUrl(<url to file>);
var fileStream = file.OpenBinaryStream();
clientContext.ExecuteQuery();

我有例外

File Not Found

即使使用 https://developer.microsoft.com/en-us/graph/graph-explorer 我也无法访问我的文件

我还可以使用 SharePoint CSOM 下载文件 <公司>.sharepoint.com/Shared%20Documents/Forms/AllItems.aspx

有没有办法直接从员工文档库下载文件,或者它被禁止,我应该将所有文件移动到 SharePoint 'Communication site' 文档?

我像本教程中那样使用 Azure Active Directory 应用程序解决了这个问题 https://docs.microsoft.com/en-us/graph/auth-v2-service