phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Attempted to perform an unauthorized operation

Open PIKACHUIM opened this issue 2 years ago • 0 comments

I have create my app and grant permissions to the app by add xml:

<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>

But here is giving errors:

Fatal error: Uncaught Office365\Runtime\Http\RequestException: 
{"error":{"code":"-2147024891, System.UnauthorizedAccessException",
"message":{"lang":"zh-CN","value":"Attempted to perform an unauthorized operation."}}}

Here is my code:

require_once 'vendor/autoload.php';
use Office365\Runtime\Auth\UserCredentials;
use Office365\Runtime\Auth\ClientCredential;
use Office365\SharePoint\ClientContext;
use Office365\SharePoint\ListItem;
$credentials = new ClientCredential("xxxxxx", "xxxxxx");
$ctx = (new ClientContext("https://xxxxxx.sharepoint.com/sites/file"))->withCredentials($credentials);
$list = $ctx->getWeb()->getLists()->getByTitle("Documents");
$items = $list->getItems();
$ctx->load($items);
$ctx->executeQuery();

Many thanks !

PIKACHUIM avatar Feb 19 '22 13:02 PIKACHUIM