Microsoft 365 Library for PHP.
Added
GraphServiceClient::withUserCredentials
and GraphServiceClient::withClientSecret
methods introducedFixed
GraphServiceClient
$siteUrl = "https://contoso.sharepoint.com"; //site or web absolute url
$tenant = "contoso.onmicrosoft.com"; //tenant id or name
$thumbprint = "--thumbprint goes here--";
$clientId = "--client app id goes here--";
$privateKetPath = "-- path to private.key file--"
$privateKey = file_get_contents($privateKetPath);
$ctx = (new ClientContext($siteUrl))->withClientCertificate(
$tenant, $clientId, $privateKey, $thumbprint);
$whoami = $ctx->getWeb()->getCurrentUser()->get()->executeQuery();
print $whoami->getLoginName();
$credentials = new ClientCredential($clientId, $clientSecret);
$client = (new ClientContext($siteUrl))->withCredentials($credentials);
$docSetName = "Orders";
$lib = $client->getWeb()->defaultDocumentLibrary();
$docSet = DocumentSet::create($client, $lib->getRootFolder(), $docSetName)->executeQuery();
print($docSet->getProperty("ServerRelativeUrl"));
CcRecipients
property to Message
class by @DavidBrogliClientObjectCollection
class enhancements, introduced getAll
method by @vgremExample: read list items in a large list via getAll
method:
$ctx = (new ClientContext($siteUrl))->withCredentials($credentials);
$list = $ctx->getWeb()->getLists()->getByTitle("--large list title--");
$allItems = $list->getItems()->getAll(5000, function ($returnType){
print("{$returnType->getPageInfo()} items loaded...\n");
})->executeQuery();
acquireTokenForPassword
method in AADTokenProvider
class by @R-Techcomposer.json
by @cweiskePHP 8
and drop PHP 5.5
requirement by @cweiskeFieldLookupValue/FieldMultiLookupValue
, FieldMultiChoiceValue
, refer example 1
below ( related issues: #261)$list = $ctx->getWeb()->getLists()->getByTitle("Tasks");
$taskProps = array(
'Title' => "New task",
'ParentTask' => new FieldLookupValue($taskLookupId),
'PrimaryManager' => new FieldUserValue($userId),
'Managers' => new FieldMultiLookupValue([$userId]),
'TaskCategories' => new FieldMultiChoiceValue(["Event", "Reminder"])
);
$item = $list->addItem($taskProps)->executeQuery();
Reports
namespace, refer official documentation for a more detailsOutlook
namespace model updates16.0.21729.12001
versionExample: Get details about Microsoft 365 active users
Documentation: reportRoot: getOffice365ActiveUserDetail
use Office365\GraphServiceClient;
use Office365\Runtime\Auth\AADTokenProvider;
use Office365\Runtime\Auth\ClientCredential;
function acquireToken()
{
$resource = "https://graph.microsoft.com";
$provider = new AADTokenProvider($tenantName);
return $provider->acquireTokenForClientCredential($resource,
new ClientCredential($clientId, $clientSecret),["/.default"]);
}
$client = new GraphServiceClient("acquireToken");
$result = $client->getReports()->getOffice365ActivationCounts()->executeQuery();
var_dump($result->getValue());
$result = $client->getReports()->getOffice365ActiveUserDetail("D7")->executeQuery();
var_dump($result->getValue());