【问题标题】:How to access shared files on SharePoint in PHP?如何在 PHP 中访问 SharePoint 上的共享文件?
【发布时间】:2019-08-19 18:47:04
【问题描述】:

我对 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";

【问题讨论】:

    标签: php sharepoint


    【解决方案1】:

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

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

    【讨论】:

    • 其实是认证过程失败了。对“login.microsoftonline.com/getuserrealm.srf?login={username}&xml=1”的调用成功,它会获取 SAML 令牌,但是当尝试通过将令牌提交到 sharepoint 上的“/_forms/default.aspx?wa=wsignin1.0”来交换令牌时,它失败并出现此错误:问题类型:来宾用户正在登录,但外部共享已禁用。我在上面发布的代码调用 API /_api/web/GetFileByServerRelativeUrl('/sites/SubSiteName/Shared Documents/OurCompanyName/Invoice/INV_123.PDF') 在浏览器中,它向我发送文件信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 2017-12-14
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多