I’m using Microsoft Graph Api (PHP->msGraph SDK) to create online meetings. I’m Facing 403 error can someone help me out.
$clientId = "***********************************"; $clientSecret = "***********************************"; $tenantId = '***********************************'; $responseUri = "http://localhost:8888/moodle39"; $guzzle = new GuzzleHttpClient(); $url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/v2.0/token'; $token = json_decode($guzzle->post($url, [ 'form_params' => [ 'client_id' => $clientId, 'client_secret' => $clientSecret, 'scope' => 'https://graph.microsoft.com/.default', 'grant_type' => 'client_credentials', ], ])->getBody()->getContents()); $accessToken = $token->access_token; //Create a new Graph client. $graph = new Graph(); $graph->setAccessToken($accessToken); $onlinemeet->startDateTime = "2020-09-02T14:30:34.2444915"; $onlinemeet->endDateTime = "2020-09-02T15:30:34.2444915"; $onlinemeet->subject = "Test Meeting"; $jso = json_encode($onlinemeet); $user = $graph->createRequest("POST", "/me/onlineMeetings")->addHeaders(array("Content-Type" => "application/json"))->attachBody($jso)->setReturnType(User::class) ->execute();
Exception – Client error: POST https://graph.microsoft.com/beta/me/onlineMeetings resulted in a 403 Forbidden response: { “error”: { “code”: “Forbidden”, “message”: “”, “innerError”: { “request-id”: “bd43aa57-511e-4 (truncated…)
While creating an application in azure portal
under API permission i gave permission to access
GraphApi->Delegated Permissions->onlinemeetings.ReadWrite.
Can someone help me with a proper example or proper syntax in PHP.
Thankyou !!..
Advertisement
Answer
You cannot use the client credential flow to get the token to call the /me endpoint. For the client credential flow, it is usually used for server-to-server interactions that must run in the background and do not interact with the user immediately(No user logged in). For the /me endpoint, it is usually User login is required, so you should use auth code flow.
By the way, APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. Therefore, it is recommended that you use the /v1.0 version.
please see:here.
Update:
There are many similar samples, I hope they can help you: