命名空间:microsoft.graph
创建 calendarPermission 资源,以指定与其共享或委托指定日历的用户的标识和角色。
此 API 可用于以下国家级云部署。
| 全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
| ✅ |
✅ |
✅ |
✅ |
权限
根据事件所处日历类型和所请求的权限类型(委派型或应用程序),需要下列某一权限来调用此 API。 要了解详细信息(包括如何选择权限),请参阅权限。
| 日历 |
委派(工作或学校帐户) |
委派(个人 Microsoft 帐户) |
应用程序 |
| 用户日历 |
Calendars.Read、Calendars.ReadWrite |
Calendars.Read、Calendars.ReadWrite |
Calendars.Read、Calendars.ReadWrite |
| 组日历 |
Group.Read.All、Group.ReadWrite.All |
不支持。 |
不支持。 |
HTTP 请求
创建用户主日历的指定权限:
POST /users/{id}/calendar/calendarPermissions
创建组日历的指定权限:
POST /groups/{id}/calendar/calendarPermissions
创建包含标识事件的用户日历的指定权限:
POST /users/{id}/events/{id}/calendar/calendarPermissions
| 名称 |
说明 |
| Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
| Content-Type |
application/json. 必需。 |
请求正文
在请求正文中,提供 calendarPermission 对象的 JSON 表示形式。
响应
如果成功,此方法在响应正文中返回响应 200 OK 代码和 calendarPermission 对象的集合。
示例
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/v1.0/me/calendar/calendarPermissions
{
"emailAddress": {
"name": "Samantha Booth",
"address": "samanthab@contoso.com"
},
"isInsideOrganization": true,
"isRemovable": true,
"role": "read"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new CalendarPermission
{
EmailAddress = new EmailAddress
{
Name = "Samantha Booth",
Address = "samanthab@contoso.com",
},
IsInsideOrganization = true,
IsRemovable = true,
Role = CalendarRoleType.Read,
};
// 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.CalendarPermissions.PostAsync(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.NewCalendarPermission()
emailAddress := graphmodels.NewEmailAddress()
name := "Samantha Booth"
emailAddress.SetName(&name)
address := "samanthab@contoso.com"
emailAddress.SetAddress(&address)
requestBody.SetEmailAddress(emailAddress)
isInsideOrganization := true
requestBody.SetIsInsideOrganization(&isInsideOrganization)
isRemovable := true
requestBody.SetIsRemovable(&isRemovable)
role := graphmodels.READ_CALENDARROLETYPE
requestBody.SetRole(&role)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
calendarPermissions, err := graphClient.Me().Calendar().CalendarPermissions().Post(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);
CalendarPermission calendarPermission = new CalendarPermission();
EmailAddress emailAddress = new EmailAddress();
emailAddress.setName("Samantha Booth");
emailAddress.setAddress("samanthab@contoso.com");
calendarPermission.setEmailAddress(emailAddress);
calendarPermission.setIsInsideOrganization(true);
calendarPermission.setIsRemovable(true);
calendarPermission.setRole(CalendarRoleType.Read);
CalendarPermission result = graphClient.me().calendar().calendarPermissions().post(calendarPermission);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const calendarPermission = {
emailAddress: {
name: 'Samantha Booth',
address: 'samanthab@contoso.com'
},
isInsideOrganization: true,
isRemovable: true,
role: 'read'
};
await client.api('/me/calendar/calendarPermissions')
.post(calendarPermission);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\CalendarPermission;
use Microsoft\Graph\Generated\Models\EmailAddress;
use Microsoft\Graph\Generated\Models\CalendarRoleType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CalendarPermission();
$emailAddress = new EmailAddress();
$emailAddress->setName('Samantha Booth');
$emailAddress->setAddress('samanthab@contoso.com');
$requestBody->setEmailAddress($emailAddress);
$requestBody->setIsInsideOrganization(true);
$requestBody->setIsRemovable(true);
$requestBody->setRole(new CalendarRoleType('read'));
$result = $graphServiceClient->me()->calendar()->calendarPermissions()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Calendar
$params = @{
emailAddress = @{
name = "Samantha Booth"
address = "samanthab@contoso.com"
}
isInsideOrganization = $true
isRemovable = $true
role = "read"
}
# A UPN can also be used as -UserId.
New-MgUserCalendarPermission -UserId $userId -BodyParameter $params
有关如何将 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_permission import CalendarPermission
from msgraph.generated.models.email_address import EmailAddress
from msgraph.generated.models.calendar_role_type import CalendarRoleType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = CalendarPermission(
email_address = EmailAddress(
name = "Samantha Booth",
address = "samanthab@contoso.com",
),
is_inside_organization = True,
is_removable = True,
role = CalendarRoleType.Read,
)
result = await graph_client.me.calendar.calendar_permissions.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('458d4c95-124e-49da-ba9d-1dd0387e682e')/calendar/calendarPermissions/$entity",
"id": "RXhjaGFuZ2VQdWJsaXNoZWRVc2VyLnNhbWFudGhhYkBhZGF0dW0ub25taWNyb3NvZnQuY29t",
"isRemovable": true,
"isInsideOrganization": true,
"role": "read",
"allowedRoles": [
"freeBusyRead",
"limitedRead",
"read"
],
"emailAddress": {
"name": "Samantha Booth",
"address": "samanthab@contoso.com"
}
}