I’m trying to make an calendar view for my company to show which employees are available. I made an app in Azure, I can logon in to the system, I get an access token, but I can’t get information.
I build the request url using curl and send this header with my request
array(6) { [0]=> string(28) "User-Agent: php-tutorial/1.0" [1]=> string(588) "Authorization: Bearer ~ACCESS_TOKEN~" [2]=> string(24) "Accept: application/json" [3]=> string(55) "client-request-id: ~GUID~" [4]=> string(30) "return-client-request-id: true" [5]=> string(45) "X-AnchorMailbox: ~MAIL~" }
And all I get as a response is: ” “
What am I doing wrong?
UPDATE
After logging in, Microsoft does not ask if i want to grant access to the app, but it does grant me an access token. Could this be the problem? And how can I make it ask for permission?
UPDATE 2
After logging in and trying to get information, I get a 401 Error saying: Access denied. Which is strange I think cause it already granted me an access token.
UPDATE 3
Couple days further and I have tried some example and tutorial code to check if it works. But even in these apps the api seem not to work. These are the projects I have tried.
https://github.com/microsoftgraph/php-connect-rest-sample
https://dev.outlook.com/restapi/tutorial/php
Advertisement
Answer
According the error list at https://graph.microsoft.io/en-us/docs/overview/errors, when you get the 401 error, it means
Required authentication information is either missing or not valid for the resource.
It may be that your access token doesn’t contain the scope for the resource your application requesting. E.g.
If you want to list the resource of calendar view, and according the document at https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_list_calendarview:
One of the following scopes is required to execute this API:
Calendars.Read
;Calendars.ReadWrite
Please login the portal of your Azure AD application, check the permissions Have full access to user calendars
or Read user calendars
of Microsoft Graph whether have been marked.
And you can check the “scope” section of the response body with your access token, refer to https://azure.microsoft.com/en-us/documentation/articles/active-directory-protocols-oauth-code/#use-the-authorization-code-to-request-an-access-token for more info.