命名空间:microsoft.graph
更新 calendar 对象的属性。 可以是用户的日历,也可以是 Microsoft 365 组的默认日历。
此 API 可用于以下国家级云部署。
| 全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
| ✅ |
✅ |
✅ |
✅ |
权限
根据事件所处日历类型和所请求的权限类型(委派型或应用程序),需要下列某一权限来调用此 API。 要了解详细信息(包括如何选择权限),请参阅权限。
| 日历 |
委派(工作或学校帐户) |
委派(个人 Microsoft 帐户) |
应用程序 |
| 用户日历 |
Calendars.ReadWrite |
Calendars.ReadWrite |
Calendars.ReadWrite |
| 组日历 |
Group.ReadWrite.All |
不支持。 |
不支持。 |
HTTP 请求
用户或组的默认 日历。
PATCH /me/calendar
PATCH /users/{id | userPrincipalName}/calendar
PATCH /groups/{id}/calendar
默认 calendarGroup 中用户的 日历。
PATCH /me/calendars/{id}
PATCH /users/{id | userPrincipalName}/calendars/{id}
指定 calendarGroup 中用户的 日历。
PATCH /me/calendarGroups/{id}/calendars/{id}
PATCH /users/{id | userPrincipalName}/calendarGroups/{id}/calendars/{id}
| 标头 |
值 |
| Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
| Content-Type |
application/json. 必需。 |
请求正文
在请求正文中,提供应更新的相关字段的值。 请求正文中不包括的现有属性将保留其以前的值,或根据对其他属性值的更改重新计算。 为了实现最佳性能,不得添加未变化的现有值。
| 属性 |
类型 |
说明 |
| color |
String |
在 UI 中指定将该日历与其他日历区分开来的颜色主题。 属性值有:LightBlue=0、LightGreen=1、LightOrange=2、LightGray=3、LightYellow=4、LightTeal=5、LightPink=6、LightBrown=7、LightRed=8、MaxColor=9、Auto=-1 |
| isDefaultCalendar |
Boolean |
如果此日历是用户的默认日历,则值为 true,否则为 false。 |
| name |
String |
日历名称。 |
响应
如果成功,此方法在响应正文中返回 200 OK 响应代码和更新的 calendar 对象。
示例
请求
以下示例更新已登录用户的默认日历的名称。
PATCH https://graph.microsoft.com/v1.0/me/calendar
Content-type: application/json
{
"name": "Social events"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new Calendar
{
Name = "Social events",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Calendar.PatchAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewCalendar()
name := "Social events"
requestBody.SetName(&name)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
calendar, err := graphClient.Me().Calendar().Patch(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Calendar calendar = new Calendar();
calendar.setName("Social events");
Calendar result = graphClient.me().calendar().patch(calendar);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const calendar = {
name: 'Social events'
};
await client.api('/me/calendar')
.update(calendar);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\Calendar;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Calendar();
$requestBody->setName('Social events');
$result = $graphServiceClient->me()->calendar()->patch($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.calendar import Calendar
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Calendar(
name = "Social events",
)
result = await graph_client.me.calendar.patch(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
响应
以下示例显示了相应的响应。 注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#me/calendars/$entity",
"@odata.id":"https://graph.microsoft.com/v1.0/users('266efe5a-0fd7-4edd-877b-b2d1e561f193@ae01a323-3934-4475-a32d-af1274312bb0')/calendars('AAMkADJmMVAAA=')",
"id":"AAMkADJmMVAAA=",
"name":"Social events",
"color":"auto",
"isDefaultCalendar":false,
"changeKey":"DxYSthXJXEWwAQSYQnXvIgAAIxGttg==",
"canShare":true,
"canViewPrivateItems":true,
"hexColor": "",
"canEdit":true,
"allowedOnlineMeetingProviders": [
"teamsForBusiness"
],
"defaultOnlineMeetingProvider": "teamsForBusiness",
"isTallyingResponses": true,
"isRemovable": false,
"owner":{
"name":"Samantha Booth",
"address":"samanthab@contoso.com"
}
}