Hi @Dev MDSK
You should use try-catch to capture your error details to help us troubleshoot for you.
Judging from the script you provided, it should be an application-only context, so you won't be able to call the /me
endpoint to get the logged in user's calendar, only the /users/{id}
endpoint, as there is no user involved.
Also, make sure you have granted the calendars.Read
application permission to the calling app. Afterwards, remove the dynamic permissions in the script, which are not supported in the client credentials flow.
$tenantId = 'f8cdef31-a31e-4b4a-93e4-5f571e91255a';
$clientId = '981ecee8-1b95-4ce6-932d-f71ab583be34';
$clientSecret = 'zb-8Q~FB1TEFMAIv~tBNs_bPUq9HiEd6epylvcXk';
$scopes = ['https://graph.microsoft.com/.default'];
$tokenRequestContext = new ClientCredentialContext(
$tenantId,
$clientId,
$clientSecret
);
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->users()->byUserId('user-id')->calendars()->get()->wait();
print_r($result);
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.