Created
October 10, 2023 17:23
-
-
Save isvargasmsft/c9f674d60cb0ffdd502e216714fbc171 to your computer and use it in GitHub Desktop.
PHP simple initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Microsoft\Graph\GraphServiceClient; | |
use Microsoft\Kiota\Abstractions\ApiException; | |
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext; | |
set_include_path(__DIR__); | |
require 'vendor/autoload.php'; | |
$tokenRequestContext = new ClientCredentialContext( | |
'tenantID', | |
'clientID', | |
'clientSecret' | |
); | |
$graphServiceClient = new GraphServiceClient($tokenRequestContext); | |
//Get a user | |
try { | |
$response = $graphServiceClient->users()->ByUserId('AlexW@M365x86781558.OnMicrosoft.com')->get()->wait(); | |
echo "Hello, I am {$response->getGivenName()}"; | |
} catch (ApiException $ex) { | |
echo $ex->getMessage(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Microsoft\Graph\GraphServiceClient; | |
use Microsoft\Kiota\Abstractions\ApiException; | |
use Microsoft\Kiota\Authentication\Oauth\AuthorizationCodeContext; | |
set_include_path(__DIR__); | |
require 'vendor/autoload.php'; | |
$tokenRequestContext = new AuthorizationCodeContext( | |
'tenantID', | |
'clientID', | |
'value', | |
'authCode', | |
'redirectURI' | |
); | |
$scopes = ['User.Read']; | |
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes); | |
try { | |
$user = $graphServiceClient->me()->get()->wait(); | |
echo "Hello, I am {$user->getGivenName()}"; | |
} catch (ApiException $ex) { | |
echo $ex->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment