phpSPO
phpSPO copied to clipboard
QUESTION: Falling at the first hurdle - connection error? PHP Fatal error: Uncaught Office365\Runtime\Http\RequestException
Hi I am basically copying the examples from the README and this is my code
<?php
require_once 'vendor/autoload.php';
use Office365\Runtime\Auth\ClientCredential;
use Office365\SharePoint\ClientContext;
$credentials = new ClientCredential("{client_id}", "{client_secret}");
$client = (new ClientContext("https://{site}.sharepoint.com/"))->withCredentials($credentials);
$items = $client->getWeb()
->getLists()
->getByTitle("{list-title}")
->getItems()
->get()
->executeQuery();
/** @var ListItem $item */
foreach($items as $item) {
print "Task: {$item->getProperty('Title')}\r\n";
}
I am a bit of a novice. I had tried previously to use the example code using the site / username / password example and was hitting an error thrown within SamlTokenProvider
so I thought I'd try the client_id/ secret method - the code for which we see above.
When I used an invalid secret I got the message
Fatal error: Uncaught Exception: AADSTS7000215: Invalid client secret provided.
which to me is very encouraging. When I provide the correct secret I get this message:
PHP Fatal error: Uncaught Office365\Runtime\Http\RequestException in /Users/myuser/code/scratch/croydon/vendor/vgrem/php-spo/src/Runtime/ClientRequest.php:137
Stack trace:
#0 /Users/myuser/code/scratch/croydon/vendor/vgrem/php-spo/src/Runtime/ClientRequest.php(102): Office365\Runtime\ClientRequest->validate(Object(Office365\Runtime\Http\Response))
#1 /Users/myuser/code/scratch/croydon/vendor/vgrem/php-spo/src/Runtime/OData/ODataRequest.php(128): Office365\Runtime\ClientRequest->executeQueryDirect(Object(Office365\Runtime\Http\RequestOptions))
#2 /Users/myuser/code/scratch/croydon/vendor/vgrem/php-spo/src/Runtime/ClientRequest.php(83): Office365\Runtime\OData\ODataRequest->executeQueryDirect(Object(Office365\Runtime\Http\RequestOptions))
#3 /Users/myuser/code/scratch/croydon/vendor/vgrem/php-spo/src/Runtime/ClientRuntimeContext.php(81): Office365\Runtime\ClientRequest->executeQuery(Object(Office365\Runtime\Actions\ReadEntityQuery))
#4 /Users/myuser/code/scratch/croydon/vendor/vgrem/php-spo/src/Runtime/ClientObject.php(99): Office365\Runtime\ClientRuntimeContext->executeQuery()
#5 /Users/myuser/code/scratch/croydon/sp4.php(26): Office365\Runtime\ClientObject->executeQuery()
#6 {main}
thrown in /Users/myuser/code/scratch/croydon/vendor/vgrem/php-spo/src/Runtime/ClientRequest.php on line 137
I am perplexed - is this an issue with this package, me or the config of my Sharepoint infrastructure (using by the way Office 365 - all cloud based).