为了向 an 添加权限,您必须向以下端点发出 POST 请求:
https://graph.microsoft.com/v1.0/sites/{site-id}/drive/items/{folder-id}/invite
正文包含有关邀请请求的所有信息,如下例所示:
{
"requireSignIn": false,
"sendInvitation": false,
"roles": [ "read | write"],
"recipients": [
{
"email": "{email of the user}"
}
],
"message": "string"
}
如果您的请求成功,您将收到的回复将采用以下格式:
Status: 200
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(permission)",
"value": [
{
"@odata.type": "#microsoft.graph.permission",
"id": "<some id>",
"roles": [
"write"
],
"grantedTo": {
"user": {
"email": "<user>@<tenant>.onmicrosoft.com",
"id": "<some id>",
"displayName": "<user's display name>"
}
}
}
]
}
下面我将与您分享创建成功请求后从 Graph Explorer 得到的代码 sn-p:
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var recipients = new List<DriveRecipient>()
{
new DriveRecipient
{
Email = "<user>@<tenant>.onmicrosoft.com"
}
};
var message = "Here's the file that we're collaborating on.";
var requireSignIn = true;
var sendInvitation = true;
var roles = new List<String>()
{
"write"
};
await graphClient.Sites["root"].Drive.Items["<folder-id>"]
.Invite(recipients,requireSignIn,roles,sendInvitation,message,null,null,null)
.Request()
.PostAsync();
笔记
- 您可以找到有关端点here 的文档。
- 如果您尝试将权限添加到从文档库继承其权限模型的文件夹,您应该注意,因为在某些情况下,如果用户不是网站组的成员,MS Graph 可能会在文件夹。