获取最近的用户活动

命名空间:microsoft.graph

获取给定用户的最近活动。 此 OData 函数包含一些默认行为,使它像“最近使用过”的 API 一样运行。 服务查询最新的 activityHistoryItems,然后拉取这些相关活动。 活动根据 activityHistoryItem 上的最新 LastModified 进行排序。 这意味着没有 activityHistoryItems 的活动不会包含在响应中。 UserActivity.ReadWrite.CreatedByApp 权限还将对响应应用额外的筛选,以便仅返回应用程序创建的活动。 如果用户处于活动状态,并且其他应用程序创建了较新的活动,则此服务器端筛选可能会导致空页。 若要获取应用程序的活动,请使用 nextLink 属性进行分页。

此 API 可用于以下国家级云部署。

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国
✅ ❌ ❌ ❌

权限

为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。

权限类型 最低特权权限 更高特权权限
委派(工作或学校帐户) UserActivity.ReadWrite.CreatedByApp 不可用。
委派(个人 Microsoft 帐户) UserActivity.ReadWrite.CreatedByApp 不可用。
应用程序 不支持。 不支持。

HTTP 请求

GET /me/activities/recent

可选的查询参数

此方法支持一些 OData 查询参数 来帮助自定义响应。 支持以下查询参数:

  • historyItems 导航属性的$expand。
  • $top限制跨页的最大项数。
  • $filter活动或 activityHistoryItems 的 lastModifiedDateTime 属性(如果展开)。

下面是使用 URL 编码支持的查询的一些示例。

/me/activities/recent?$expand=historyItems($filter=lastModifiedDateTime%20gt%202018-01-22T21:45:00.347Z%20and%20lastModifiedDateTime%20lt%202018-01-22T22:00:00.347Z)

/me/activities/recent?$filter=lastModifiedDateTime%20lt%202018-01-16T01:03:21.347Z%20and%20lastModifiedDateTime%20gt%202018-01-03T01:03:21.347Z

/me/activities/recent?$top=5

请求标头

名称 类型 说明
Authorization string 持有者 {token}。 必填。 详细了解 身份验证和授权。

请求正文

不要指定请求正文。

响应

如果成功,此方法将 200 OK 返回响应代码,其中包含应用程序的用户最近活动。

示例

请求

下面是请求的示例。

GET https://graph.microsoft.com/v1.0/me/activities/recent

响应

以下是响应示例。

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

{
   "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(userActivity)",
   "@odata.nextLink":"https://graph.microsoft.com/v1.0/me/activities/recent?$skiptoken=%24filter%3dlastModifiedDateTime+lt+2018-02-26T18%3a06%3a19.365Z",
   "value":[
      {
         "@odata.type":"#microsoft.graph.userActivity",
         "activitySourceHost":"https://www.contoso.com",
         "createdDateTime":"2018-02-26T18:34:29.592Z",
         "lastModifiedDateTime":"2018-02-26T18:34:29.607Z",
         "id":"5347642601316252694",
         "appActivityId":"/article?12345",
         "visualElements":{
            "attribution":{
               "iconUrl":"https://www.contoso.com/icon",
               "alternateText":"Contoso, Ltd.",
               "addImageQuery":false
            },
            "displayText":"Contoso How-To: How to Tie a Reef Knot",
            "description":"How to Tie a Reef Knot. A step-by-step visual guide to the art of nautical knot-tying.",
            "backgroundColor":"#ff0000",
            "content":{
               "$schema":"https://adaptivecards.io/schemas/adaptive-card.json",
               "type":"AdaptiveCard",
               "body":[
                  {
                     "type":"TextBlock",
                     "text":"Contoso MainPage"
                  }
               ]
            }
         },
         "activationUrl":"https://www.contoso.com/article?id=12345",
         "appDisplayName":"Contoso, Ltd.",
         "userTimezone":"Africa/Casablanca",
         "fallbackUrl":"https://www.contoso.com/article?id=12345",
         "contentUrl":"https://www.contoso.com/article?id=12345",
         "contentInfo":{
            "@context":"https://schema.org",
            "@type":"Article",
            "author":"John Doe",
            "name":"How to Tie a Reef Knot"
         },
         "expirationDateTime":"2018-03-28T18:34:29.607Z",
         "status":"updated"
      }
   ]
}