PHP code example of microsoft / microsoft-graph-core
1. Go to this page and download the library: Download microsoft/microsoft-graph-core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
microsoft / microsoft-graph-core example snippets
$tokenRequestContext = new ClientCredentialContext(
'tenantId',
'clientId',
'clientSecret'
);
// requests using https://graph.microsoft.com/.default scopes by default
$tokenProvider = new GraphPhpLeagueAccessTokenProvider($tokenRequestContext);
$token = $tokenProvider->getAuthorizationTokenAsync(GraphConstants::REST_ENDPOINT)->wait();
use Microsoft\Graph\Core\GraphClientFactory;
$guzzleConfig = [
// your preferred guzzle config
];
$httpClient = GraphClientFactory::createWithConfig($guzzleConfig);
use Microsoft\Graph\Core\GraphClientFactory;
class UsageExample
{
public function run()
{
$accessToken = 'xxx';
$config = [
'headers' => [
'Authorization' => $accessToken
]
];
$httpClient = GraphClientFactory::createWithConfig($config);
$response = $httpClient->get("/v1.0/me");
$currentUser = json_decode($response->getBody());
echo "Hello, I am {$currentUser['givenName']}";
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.