phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Impossible to retrieve any items

Open Tadaz opened this issue 4 months ago • 0 comments

I am using the latest version of 3.1.1 and SharePoint online.

The only working snippet I got using this library is below - I can retrieve the root list of lists, any other command returns an empty list.

$credentials = new \Office365\Runtime\Auth\UserCredentials("USERNAME", "PASSWORD");
$ctx = (new \Office365\SharePoint\ClientContext("URL"))->withCredentials($credentials);

foreach ($ctx->getWeb()->getLists()->get()->executeQuery() as $list) {
    dump($list->getId() . ' ' . $list->getTitle());
}

I tweaked the code above to return all items from the Documents list but it always returns an empty list.

$credentials = new \Office365\Runtime\Auth\UserCredentials("USERNAME", "PASSWORD");
$ctx = (new \Office365\SharePoint\ClientContext("URL"))->withCredentials($credentials);

foreach ($ctx->getWeb()->getLists()->get()->executeQuery() as $list) {
    if($list->getTitle() === 'Documents') {
        $listItems = $list->getItems()->get()->executeQuery();
    
        //RETURNS EMPTY LIST OF ITEMS
        foreach ($listItems as $item){
            dump($item->getTitle());
        }
    }
}

I tried other different ways as well, e.g.

$credentials = new \Office365\Runtime\Auth\UserCredentials("USERNAME", "PASSWORD");
$ctx = (new \Office365\SharePoint\ClientContext("URL"))->withCredentials($credentials);

$list = $ctx->getWeb()->getList("Shared Documents")->executeQuery();
$listItems = $list->getItems()->get()->executeQuery();

//SAME ISSUE, THE LIST IS EMPTY
foreach ($listItems as $item){
    dump($item->getTitle());
}

I have read and edit permissions for the whole project.

Any suggestions?

Tadaz avatar Feb 16 '24 11:02 Tadaz