创建或替换活动
命名空间:microsoft.graph
为应用创建新的用户活动或替换现有 用户活动 。 如果要在一个请求中创建用户活动及其相关 活动HistoryItems ,可以使用 深度插入。
权限
为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 | 最低特权权限 | 更高特权权限 |
---|---|---|
委派(工作或学校帐户) | UserActivity.ReadWrite.CreatedByApp | 不可用。 |
委派(个人 Microsoft 帐户) | UserActivity.ReadWrite.CreatedByApp | 不可用。 |
应用程序 | 不支持。 | 不支持。 |
HTTP 请求
PUT /me/activities/{appActivityId}
注意: URL 中的 appActivityId 需要是 URL 安全的, (除 RFC 2396 未保留字符之外的所有字符都必须) 转换为其十六进制表示形式,但原始 appActivityId 不必是 URL 安全。
请求标头
名称 | 类型 | 说明 |
---|---|---|
Authorization | string | 持有者 {token}。 必填。 详细了解 身份验证和授权。 |
请求正文
在请求正文中,提供 活动 对象的 JSON 表示形式。
响应
如果成功,如果已创建活动或200 OK
已替换活动,则此方法将返回201 Created
响应代码。
示例
示例 1:创建活动
请求
以下示例显示了一个请求。
PUT https://graph.microsoft.com/v1.0/me/activities/3F12345
Content-type: application/json
{
"activitySourceHost": "https://contoso.com",
"createdDateTime": "2017-06-09T20:54:43.969Z",
"lastModifiedDateTime": "2017-06-09T20:54:43.969Z",
"id": "14332800362997268276",
"appActivityId": "/article?12345",
"status": "updated",
"expirationDateTime": "2017-02-26T20:20:48.114Z",
"visualElements": {
"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.",
"attribution": {
"iconUrl": "https://www.contoso.com/icon",
"alternateText": "Contoso Ltd",
"addImageQuery": false
},
"backgroundColor": "#ff0000",
"content": {
"$schema": "https://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Contoso MainPage"
}
]
}
}
}
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-Type: application/json
{
"activitySourceHost": "https://contoso.com",
"createdDateTime": "2017-06-09T20:54:43.969Z",
"lastModifiedDateTime": "2017-06-09T20:54:43.969Z",
"id": "14332800362997268276",
"appActivityId": "/article?12345",
"status": "updated",
"expirationDateTime": "2017-02-26T20:20:48.114Z",
"visualElements": {
"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.",
"attribution": {
"iconUrl": "https://www.contoso.com/icon",
"alternateText": "Contoso, Ltd.",
"addImageQuery": false
},
"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": "Jennifer Booth",
"name": "How to Tie a Reef Knot"
}
}
示例 2:深度插入
本示例在一个请求中为该活动创建新活动和历史记录项。
请求
以下示例显示了一个请求。
PUT https://graph.microsoft.com/v1.0/me/activities/12345
Content-type: application/json
{
"activitySourceHost": "https://contoso.com",
"createdDateTime": "2017-06-09T20:54:43.969Z",
"lastModifiedDateTime": "2017-06-09T20:54:43.969Z",
"id": "14332800362997268276",
"appActivityId": "/article?12345",
"status": "updated",
"expirationDateTime": "2017-02-26T20:20:48.114Z",
"visualElements": {
"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.",
"attribution": {
"iconUrl": "https://www.contoso.com/icon",
"alternateText": "Contoso Ltd",
"addImageQuery": false
},
"backgroundColor": "#ff0000",
"content": {
"$schema": "https://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Contoso MainPage"
}
]
}
},
"historyItems": [
{
"userTimezone": "Africa/Casablanca",
"startedDateTime": "2018-02-26T20:54:04.345Z",
"lastActiveDateTime": "2018-02-26T20:54:24.345Z"
}
]
}
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-Type: application/json
{
"activitySourceHost": "https://contoso.com",
"createdDateTime": "2017-06-09T20:54:43.969Z",
"lastModifiedDateTime": "2017-06-09T20:54:43.969Z",
"id": "14332800362997268276",
"appActivityId": "/article?12345",
"status": "updated",
"expirationDateTime": "2017-02-26T20:20:48.114Z",
"visualElements": {
"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.",
"attribution": {
"iconUrl": "https://www.contoso.com/icon",
"alternateText": "Contoso, Ltd.",
"addImageQuery": false
},
"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": "Jennifer Booth",
"name": "How to Tie a Reef Knot"
},
"historyItems": [
{
"status": "updated",
"userTimezone": "Africa/Casablanca",
"createdDateTime": "2018-04-12T21:42:42.495Z",
"lastModifiedDateTime": "2018-04-12T21:42:42.495Z",
"id": "61fc8f36-919f-4b73-89d4-1cb7b159d912",
"startedDateTime": "2018-02-26T20:54:04.345Z",
"lastActiveDateTime": "2018-02-26T20:54:24.345Z",
"expirationDateTime": "2018-05-12T21:42:42.495Z",
"activeDurationSeconds": 20
}
]
}