首页 > 解决方案 > 如何在 PHP 中访问 SharePoint 上的共享文件?

问题描述

我对 SharePoint 一点也不熟悉,我正在尝试构建一个 php 脚本来浏览和访问在这样的文件夹中与我们共享的文件:https ://blabla.sharepoint.com/:b:/r/sites/ SubSiteName/Shared%20Documents/OurCompanyName/Invoice

我找到了这些库:https://github.com/vgrem/phpSPOhttps://github.com/thybag/PHP-SharePoint-Lists-API,但我找不到访问文件的好方法. 我还在这里找到了谈到 php 和 SharePoint 的帖子,但似乎没有一个符合我的需要。

我已经用 phpSPO 尝试过这段代码,但它在 executeQuery() 失败:

$authCtx = new AuthenticationContext('https://blabla.sharepoint.com');
$authCtx->acquireTokenForUser('our@email','password');
$ctx = new ClientContext('https://blabla.sharepoint.com',$authCtx);

$fileUrl = '/sites/SubSiteName/Shared Documents/OurCompanyName/Invoice/INV_123.PDF';
$file = $ctx->getWeb()->getFileByServerRelativeUrl($fileUrl);
$ctx->load($file);
$ctx->executeQuery();
print "File name: '{$file->getProperty("Name")}'\r\n";

标签: phpsharepoint

解决方案


SharePoint 具有可用于获取特定文件的 REST API

url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files('file name')/$value
method: GET

推荐阅读