我在SharePoint 365中使用PHP rest API上传文件,我正在使用SharePoint-OAuth-app-client库(https://github.com/wearearchitect/sharepoint-oauth-app-client)。因为我得到了accessstoken,但当我尝试执行文件夹列表代码时,我收到了403错误。
// 工作代码
require 'vendor/autoload.php';
use WeAreArchitect\SharePoint\SPException;
use WeAreArchitect\SharePoint\SPList;
use WeAreArchitect\SharePoint\SPSite;
use WeAreArchitect\SharePoint\SPFile;
use WeAreArchitect\SharePoint\SPFolder;
try {
$settings = [
'site' => [
'resource' => '00000000-0000-ffff-0000-000000000000/example.sharepoint.com@09g7c3b0-f0d4-416d-39a7-09671ab91f64',
'client_id' => '52848cad-bc13-4d69-a371-30deff17bb4d/example.com@09g7c3b0-f0d4-416d-39a7-09671ab91f64',
'secret' => 'YzcZQ7N4lTeK5COin/nmNRG5kkL35gAW1scrum5mXVgE=',
]
];
// create a SharePoint Site instance
$site = SPSite::create('https://example.sharepoint.com/sites/mySite/', $settings);
// generate an Access Token (App-only Policy)
$site->createSPAccessToken();
//来自此处的错误
// get a Folder by relative URL
$folder = SPFolder::getByRelativeUrl($site, 'myFolder');
// get a List by title
$folder = SPList::getByTitle($site, 'My List');
// get all the Files from the Folder/List we just got
$files = SPFile::getAll($folder);
// do something with the files
foreach ($files as $file) {
var_dump($file);
}
答案 0 :(得分:0)
经过漫长的R& D我已经解决了这个问题,因为我忘了添加SharePoint应用程序的权限,在下面的URL中我已经解释了上传文件的所有步骤。 https://rgknowledgebase.wordpress.com/2017/07/14/php-file-upload-rest-api-to-shairepoint/