【问题标题】:Creating events in calendar with Graph API returns "ResourceNotFound"使用 Graph API 在日历中创建事件会返回“ResourceNotFound”
【发布时间】:2020-08-31 22:29:30
【问题描述】:

我正在尝试使用 Graph API 在我的个人日历(Office 365 帐户)中创建事件。我在 Azure 上的租户上创建了一个实例,具有以下委派权限:Calendars.ReadCalendars.ReadWriteemailoffline_accessopenidprofileUser.Read

oAuth2 登录按预期进行,我使用/.default 范围同时收到bearer_tokenrefresh_token。但是当我尝试提出请求时:

POST /v1.0/me/calendar/events HTTP/1.1
Host: graph.microsoft.com
Authorization: Bearer eyJ0eXAi...
Content-Type: application/json

{
    "subject": "Example",
    "body": {
        "contentType": "text",
        "content": "Example description"
    },
    "start": {
        "dateTime": "2020-09-01T12:00:00.000Z",
        "timeZone": "America/Sao_Paulo"
    },
    "end": {
        "dateTime": "2020-09-01T13:00:00.000Z",
        "timeZone": "America/Sao_Paulo"
    },
    "location": {
        "displayName": "Example location",
        "locationUri": "https://example/uri"
    }
}

我收到以下回复:

{
  "error": {
    "code": "ResourceNotFound",
    "message": "Resource could not be discovered.",
    "innerError": {
      "date": "2020-08-31T22:18:15",
      "request-id": "f03d0bdf-1a9c-41f4-a236-1c5a41a5d286"
    }
  }
}

我已经发现这是一个邮箱问题,因为使用Graph Explorer 我可以提出请求并更改我的日历,所以我愿意认为这是一个权限问题。

【问题讨论】:

    标签: microsoft-graph-api


    【解决方案1】:

    我发现,问题不在于 Graph 请求,而在于身份验证请求。

    当您使用合作帐户登录 Graph API 时,获取 bearer_token 的请求是:

    • https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize
    • https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token

    但是当您使用个人帐户时,端点是:

    • https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize
    • https://login.microsoftonline.com/consumers/oauth2/v2.0/token

    使用tenantId会进行身份验证,但是在租户中找不到用户数据,给出我得到的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-12
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多