PHP code example of ssswang / sharepoint-oauth-app-client
1. Go to this page and download the library: Download ssswang/sharepoint-oauth-app-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ssswang / sharepoint-oauth-app-client example snippets
eAreArchitect\SharePoint\SPException;
use WeAreArchitect\SharePoint\SPList;
use WeAreArchitect\SharePoint\SPSite;
//Get credential instuctions https://github.com/ssswang/sharepoint-oauth-app-client/blob/master/docs/Credentials.md
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();
$site->createSPFormDigest();
$folder = SPFolder::getByRelativeUrl($site, 'IT API Test Library');
$newFolder = SPFolder::create($folder, "2019/06", []);
echo "Write to IT API Test Library...\n";
$name = "test.pdf";
$content = fopen(storage_path($name), 'r');
$this->uploadFile($site, 'IT API Test Library/2019/06', $name, $content);
// 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
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.