The SharePoint OAuth App Client is a PHP library that makes it easy to authenticate via OAuth2 with the SharePoint Online (2013) REST API and work with Lists, Folders, Items, Files and Users.
This library aims for PSR-1, PSR-2 and PSR-4 standards compliance.
composer require "wearearchitect/sharepoint-oauth-app-client:0.9.*"
<?php
require 'vendor/autoload.php';
use WeAreArchitect\SharePoint\SPException;
use WeAreArchitect\SharePoint\SPList;
use WeAreArchitect\SharePoint\SPSite;
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 all the Lists and respective Items
$lists = SPList::getAll($site, [
'fetch' => true,
]);
// iterate through each List
foreach ($lists as $list) {
var_dump($list);
// iterate through each List Item
foreach ($list as $item) {
var_dump($item);
}
}
} catch (SPException $e) {
// handle exceptions
}
See how to generate the SharePoint credentials here.
Check for common library issues and how to solve them
- Working with lists and list items with REST
- Working with folders and files with REST
- Files and folders REST API reference
The MIT License (MIT). Please see License File for more information.