使用 Microsoft 搜索 API 搜索日历事件Use the Microsoft Search API to search calendar events

使用 Microsoft 搜索 API 搜索登录用户的主日历中的事件。Use the Microsoft Search API to search for events in the signed-in user’s primary calendar. 搜索的用户标识基于身份验证令牌。The user identity for the search is based on the auth token.

注意

搜索 API 架构在 beta 版本中已更改,搜索请求和响应中的某些属性已重命名或删除。The search API schema has changed in the beta version with some properties in a search request and response renamed or removed. 查找有关弃用的更多详细信息See more details about the deprecation. 本主题中的示例显示了在 v1.0 和 beta 版中使用最新的架构。Examples in this topic show the up-to-date schema to use in v1.0 and beta.

示例Example

请求Request

本示例将在用户的日历中搜索关键字 "contoso",并返回最大25个结果。This example searches in the user's calendar for the keyword "contoso", and will return up to 25 results.

POST https://graph.microsoft.com/v1.0/search/query
Content-Type: application/json

{
  "requests": [
    {
      "entityTypes": [
        "event"
      ],
      "query": {
        "queryString":"contoso"
      },
      "from": 0,
      "size": 25
    }
  ]
}

响应Response

HTTP/1.1 200 OK
Content-type: application/json

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#search",
  "value": [
  {
   "@odata.type": "#microsoft.graph.searchResponse",
   "searchTerms": [
    "contoso"
   ],
   "hitsContainers": [
    {
     "@odata.type": "#microsoft.graph.searchHitsContainer",
     "hits": [
      {
       "@odata.type": "#microsoft.graph.searchHit",
       "hitId": "AAMkADEwODY2NzllLTQ3MmEtNGRlMC05ZTUyLTE4ZDRhYmU1ZGM3NABGAAAAAAA3+iYQBnJnQabRVDelNhnzBwAejhWkAOAxQ6M4c1c9NwfrAAAAAAENAAAejhWkAOAxQ6M4c1c9NwfrAABbUZLJAAA=",
       "rank": 1,
       "summary": "Here is a summary of your events from last week",
       "resource": {
        "@odata.type": "#microsoft.graph.event",
        "end": {
         "dateTime": "2020-06-16T04:15:00Z",
         "timeZone": "UTC"
        },
        "hasAttachments": false,
        "iCalUId": "040000008200E00074C5B7101A82E008000000007093FDD79B3AD60100000000000000001000000036DAA2262EB4E04DA27DA77985FB8251",
        "isAllDay": false,
        "sensitivity": "Normal",
        "start": {
         "dateTime": "2020-06-16T03:30:00Z",
         "timeZone": "UTC"
        },
        "subject": "Weekly digest: Microsoft 365 changes",
        "type": "Single"
       }
      }
     ],
     "total": 1,
     "moreResultsAvailable": false
    }
   ]
  }
 ]
}

已知限制Known limitations

  • 您只能访问登录用户自己的邮箱。You can access only the signed-in user’s own mailbox. 不支持搜索委派的邮箱。Searching delegated mailboxes is not supported.
  • 对于事件, searchHitsContainer类型的 total 属性包含页面上的结果数,而不是匹配结果的总数。For events, the total property of the searchHitsContainer type contains the number of results on the page, not the total number of matching results.
  • 事件不支持排序结果。Sorting results is not supported for events. 请求中的 sort 子句将在响应中返回错误的请求错误代码。A sort clause in the request will return a Bad Request error code in the response.

后续步骤Next steps