phpSPO
phpSPO copied to clipboard
Cannot get OneNote to work ???
I am trying to connect to a Sharepoint Online instance as a specific user and then get the notes:
My code is as follows:
`<?php use Office365\PHP\Client\OneNote\OneNoteClient; use Office365\PHP\Client\Runtime\Auth\AuthenticationContext; use Office365\PHP\Client\Runtime\Auth\NetworkCredentialContext; use Office365\PHP\Client\Runtime\Auth\OAuthTokenProvider; use Office365\PHP\Client\Runtime\Utilities\ClientCredential; use Office365\PHP\Client\Runtime\Utilities\UserCredentials; use Office365\PHP\Client\SharePoint\ClientContext; use Office365\PHP\Client\SharePoint\FieldType; use Office365\PHP\Client\OneDrive\OneDriveClient; use Office365\PHP\Client\Runtime\ClientRuntimeContext;
require_once 'bootstrap.php'; global $AppSettings; global $Settings;
var_dump($Settings);
try { $authorityUrl = OAuthTokenProvider::$AuthorityUrl . $AppSettings['TenantName']; //$authorityUrl = $Settings['OneDriveUrl']; //$authorityUrl = $Settings['Url']; $authCtx = new AuthenticationContext($authorityUrl); //$clientCredentials = new ClientCredential($AppSettings['ClientId'], $AppSettings['ClientSecret']); //$authCtx->acquireTokenForClientCredential("https://graph.microsoft.com", $clientCredentials); //$userCredentials = new UserCredentials($Settings['UserName'], $Settings['Password']); //$authCtx->acquireTokenForUserCredential("https://graph.microsoft.com", $AppSettings['ClientId'], $userCredentials); //$authCtx = new NetworkCredentialContext($Settings['UserName'], $Settings['Password']); $authCtx->acquireTokenForUser($Settings['UserName'], $Settings['Password']); var_dump($authCtx); //$context = new OneDriveClient($authorityUrl, $authCtx); $context = new OneNoteClient($authCtx); $notes = $context->getMe()->getNotes(); $context->load($notes); $context->executeQuery(); //echo "Number of files: " . $files->getCount(); //var_dump($files->getData()); var_dump($notes->getData()); //var_dump($files); } catch (Exception $e) { echo 'Authentication failed: ', $e->getMessage(), "\n"; }`
The error I am getting is
Authentication failed: Error trying to get a token, check your URL or credentials
However, I did check the credentials of the user I am using and the credentials ARE correct.
What am I missing ?
I am using version 2.2.0 of PHP-SPO
Thanks !