Skip to content

Instantly share code, notes, and snippets.

@vgrem
Last active March 26, 2016 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/3e53826d47ac2336330a to your computer and use it in GitHub Desktop.
Save vgrem/3e53826d47ac2336330a to your computer and use it in GitHub Desktop.
<?php
$username = 'username@tenant.onmicrosoft.com';
$password = 'password';
$url = "https://tenant.sharepoint.com/";
try {
$authCtx = new AuthenticationContext($Url);
$authCtx->acquireTokenForUser($username,$password);
$ctx = new ClientContext($Url,$authCtx);
printTasks($ctx);
}
catch (Exception $e) {
echo 'Authentication failed: ', $e->getMessage(), "\n";
}
function printTasks(ClientContext $ctx){
$listTitle = 'Tasks';
$web = $ctx->getWeb();
$list = $web->getLists()->getByTitle($listTitle);
$items = $list->getItems();
$ctx->load($items);
$ctx->executeQuery();
foreach( $items->getData() as $item ) {
print "Task: '{$item->Title}'\r\n";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment