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 | |
// v1.x | |
$accessToken = getAccessToken(); // custom token retrieval method | |
$graph = new Graph(); | |
$graph->setAccessToken($accessToken); | |
$graph ->createRequest('GET', '/me') | |
->setAccessToken(getAccessToken()) //after initial token expires | |
... |
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 | |
// v1.x | |
$response = $graphClient->createRequest('GET', '/users/userId/messages') | |
->setReturnType(Model\User::class) | |
->execute(); | |
// v2.0-RC | |
$response = $graphServiceClient->usersById('userId')->messages()->get()->wait(); |
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
# Example using async credentials and application access. | |
from azure.identity.aio import ClientSecretCredential | |
from msgraph import GraphServiceClient | |
credential = ClientSecretCredential( | |
'TENANT_ID', | |
'CLIENT_ID', | |
'CLIENT_SECRET', | |
) | |
scopes = ['https://graph.microsoft.com/.default'] |
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
client = GraphServiceClient(credentials=credential, scopes=scopes) | |
# GET /users/{id | userPrincipalName} | |
async def get_user(): | |
user = await client.users.by_user_id('userPrincipalName').get() |
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\GraphRequestAdapter; | |
use Microsoft\Graph\GraphServiceClient; | |
use Microsoft\Kiota\Abstractions\ApiException; | |
use Microsoft\Kiota\Authentication\PhpLeagueAuthenticationProvider; | |
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext; | |
$tokenRequestContext = new ClientCredentialContext( | |
'tenantID', | |
'clientID', |
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\Core\Tasks\PageIterator; | |
use Microsoft\Graph\Generated\Models\Message; | |
use DateTimeInterface; | |
$messages = $graphServiceClient->users()->byUserId(USER_ID)->messages()->get()->wait(); | |
$pageIterator = new PageIterator($messages, $graphServiceClient->getRequestAdapter()); | |
$counter = 0; |
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 Psr\Http\Client\NetworkExceptionInterface; | |
// create a file stream | |
$file = Utils::streamFor(fopen('fileName', 'r')); | |
// create an upload session | |
$attachmentItem = new AttachmentItem(); | |
$attachmentItem->setAttachmentType(new AttachmentType('file')); | |
$attachmentItem->setName('fileName'); |
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\Core\Requests\BatchRequestContent; | |
use Microsoft\Graph\Generated\Models\Message; | |
use Microsoft\Graph\BatchRequestBuilder; | |
use Microsoft\Graph\Core\Requests\BatchResponseItem; | |
use Microsoft\Graph\Generated\Models\Message; | |
// Create a batch request content object | |
$message = new Message(); |
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 | |
// v1.x | |
$response = $graphClient->createRequest('GET', '/users/userId/messages') | |
->setReturnType(Model\User::class) | |
->execute(); | |
// v2.0.0 | |
$response = $graphServiceClient->users()->byUserId('userId')->messages()->get()->wait(); |
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 | |
//RC5 initialization experience | |
$tokenRequestContext = new ClientCredentialContext( | |
'tenantID', | |
'clientID', | |
'clientSecret' | |
); | |
$scopes = ['https://graph.microsoft.com/.default']; | |
$authProvider = new PhpLeagueAuthenticationProvider($tokenRequestContext, $scopes); |
OlderNewer