获取用户活动

命名空间:microsoft.graph

获取给定用户的活动。 与 最近的 OData 函数不同,将返回不带历史记录的活动。 权限 UserActivity.ReadWrite.CreatedByApp 将针对响应应用额外筛选,以便仅返回由应用程序创建的活动。 如果用户特别活动并且其他应用程序已创建最近的活动,则此服务器端筛选可能会导致空页。 若要获取应用程序的活动,请使用 nextLink 属性分页。

权限

要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限

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

HTTP 请求

GET /me/activities

可选的查询参数

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

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

以下是使用 URL 编码的受支持查询的一些示例:

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

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

/me/activities?$top=5

请求标头

名称 类型 说明
Authorization string Bearer {token}。必需。

请求正文

无请求正文。

响应

如果成功,此方法将返回 200 OK 响应代码以及应用程序的用户活动。

示例

请求

下面展示了示例请求。

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

下面展示了示例响应。

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?$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"
    }]
}