I am using PHP rest API in SharePoint 365 to upload the file, I am using SharePoint-OAuth-app-client library (https://github.com/wearearchitect/sharepoint-oauth-app-client). In that I got accesstoken but when I try to execute folder list code I getting 403 error.
//Working code
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();
//Error From here
// 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);
}