-2

请不要报告重复,因为所有其他主题都没有解决我的问题,谢谢。

我正在使用 Microsoft Graph api 来列出和创建日历事件,但是我似乎无法使 findMeetingTimes 端点工作。

这是我的授权网址:

https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=xxxxx&response_type=code&redirect_uri=xxxxx&response_mode=form_post&scope=openid%20profile%20User.ReadWrite%20User.ReadBasic.All%20Sites.ReadWrite.All%20Contacts.ReadWrite%20People.Read%20Notes.ReadWrite.All%20Tasks.ReadWrite%20Mail.ReadWrite%20Files.ReadWrite.All%20Calendars.ReadWrite&state=12345

然后我使用相同的范围请求访问令牌:

$request = json_decode($guzzle->post('https://login.microsoftonline.com/common/oauth2/v2.0/token', [
            'headers' => [
                'Content-Type' => 'application/x-www-form-urlencoded'
            ],
            'form_params' => [
                'client_id' => 'xxxxx',
                'scope' => 'openid profile User.ReadWrite User.ReadBasic.All Sites.ReadWrite.All Contacts.ReadWrite People.Read Notes.ReadWrite.All Tasks.ReadWrite Mail.ReadWrite Files.ReadWrite.All Calendars.ReadWrite',
                'code' => $auth_code,
                'grant_type' => 'authorization_code',
                'redirect_uri' => 'xxxxx',
                'client_secret' => 'xxxxx'
            ],
        ])->getBody()->getContents());

之后,我尝试使用 findMeetingTimes 端点:

$request = json_decode($guzzle->post('https://graph.microsoft.com/v1.0/me/findMeetingTimes', [
            'headers' => [
                'Authorization' => 'Bearer ' . $accessToken,
                'Content-Type' => 'application/json',
            ],
            'body' => '{
              "attendees": [
                {
                  "type": "required",
                  "emailAddress": {
                    "name": "My Name",
                    "address": "myemail@hotmail.com"
                  }
                }
              ],
              "timeConstraint": {
                "activityDomain":"work",
                "timeslots": [
                  {
                    "start": {
                      "dateTime": "2019-04-02T09:00:00",
                      "timeZone": "Pacific Standard Time"
                    },
                    "end": {
                      "dateTime": "2019-04-03T17:00:00",
                      "timeZone": "Pacific Standard Time"
                    }
                  }
                ]
              }
            }',
        ])->getBody()->getContents());

但是,它不断返回:

401 - Unauthorized: Access is denied due to invalid credentials.

You do not have permission to view this directory or page using the credentials that you supplied.

谁将成为我的英雄?:/

4

1 回答 1

4

这是设计使然。从文档中:

注意findMeetingTimes操作当前适用于 Office 365 工作或学校邮箱,但不适用于个人 Outlook.com 邮箱。

于 2019-04-01T13:46:12.063 回答