Skip to content

Instantly share code, notes, and snippets.

@vgrem

vgrem/SPOFirstExample.php

Last active Mar 26, 2016
Embed
What would you like to do?
<?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
You can’t perform that action at this time.