|
| 1 | +<?php |
| 2 | + |
| 3 | + |
| 4 | +use Office365\PHP\Client\GraphClient\GraphServiceClient; |
| 5 | +use Office365\PHP\Client\Runtime\Auth\AuthenticationContext; |
| 6 | +use Office365\PHP\Client\Runtime\Auth\OAuthTokenProvider; |
| 7 | +use Office365\PHP\Client\Runtime\Utilities\UserCredentials; |
| 8 | + |
| 9 | +require_once '../bootstrap.php'; |
| 10 | + |
| 11 | +try |
| 12 | +{ |
| 13 | + $client = getAuthenticatedClient(); |
| 14 | + //downloadPhoto($client,"./myprofile.jpg"); |
| 15 | + getDriveInfo($client); |
| 16 | + |
| 17 | +} |
| 18 | +catch (Exception $e) { |
| 19 | + echo 'Error: ', $e->getMessage(), "\n"; |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +function getDriveInfo(GraphServiceClient $client){ |
| 24 | + $drive = $client->getMe()->getDrive(); |
| 25 | + $client->load($drive); |
| 26 | + $client->executeQuery(); |
| 27 | + print $drive->getProperty("webUrl"); |
| 28 | +} |
| 29 | + |
| 30 | + |
| 31 | +function downloadPhoto(GraphServiceClient $client,$targetFilePath){ |
| 32 | + $fp = fopen($targetFilePath, 'w+'); |
| 33 | + //$url = $client->getServiceRootUrl() . "me/photo\$value"; |
| 34 | + $url = $client->getServiceRootUrl() . "me/photo"; |
| 35 | + $options = new \Office365\PHP\Client\Runtime\Utilities\RequestOptions($url); |
| 36 | + //$options->StreamHandle = $fp; |
| 37 | + $content = $client->executeQueryDirect($options); |
| 38 | + fclose($fp); |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +function getAuthenticatedClient(){ |
| 43 | + global $AppSettings; |
| 44 | + global $Settings; |
| 45 | + $resource = "https://graph.microsoft.com"; |
| 46 | + $authorityUrl = OAuthTokenProvider::$AuthorityUrl . $AppSettings['TenantName']; |
| 47 | + $authCtx = new AuthenticationContext($authorityUrl); |
| 48 | + $authCtx->acquireTokenForUserCredential($resource,$AppSettings['ClientId'],new UserCredentials($Settings['UserName'],$Settings['Password'])); |
| 49 | + $client = new GraphServiceClient($authCtx); |
| 50 | + return $client; |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | + |
0 commit comments