名前空間: microsoft.graph
アクセス許可で表されるリンクへのアクセス権をユーザーに 付与します。
この API は、次の国内クラウド展開で使用できます。
グローバル サービス |
米国政府機関 L4 |
米国政府機関 L5 (DOD) |
21Vianet が運営する中国 |
✅ |
✅ |
✅ |
✅ |
アクセス許可
この API の最小特権としてマークされているアクセス許可またはアクセス許可を選択します。
アプリで必要な場合にのみ、より高い特権のアクセス許可またはアクセス許可を使用します。 委任されたアクセス許可とアプリケーションのアクセス許可の詳細については、「 アクセス許可の種類」を参照してください。 これらのアクセス許可の詳細については、 アクセス許可のリファレンスを参照してください。
アクセス許可の種類 |
最小特権アクセス許可 |
特権の高いアクセス許可 |
委任 (職場または学校のアカウント) |
Files.ReadWrite |
Files.ReadWrite.All、Sites.ReadWrite.All |
委任 (個人用 Microsoft アカウント) |
サポートされていません。 |
サポートされていません。 |
アプリケーション |
Files.ReadWrite.All |
Sites.ReadWrite.All |
HTTP 要求
POST /shares/{encoded-sharing-url}/permission/grant
パス パラメーター
パラメーター名 |
値 |
説明 |
encoded-sharing-url |
string |
必須です。 適切にエンコードされた共有 URL。 |
共有 URL をエンコードする
共有 URL をエンコードするには、次のロジックを使用します。
- まず、base64 を使用して URL をエンコードします。
- base64 でエンコードされた結果を unpadded base64url 形式に変換します (値の末尾から
=
文字を削除し、/
を _
、+
を -
に置き換える)。
- 文字列の先頭に
u!
を追加します。
C# で URL をエンコードする例を以下に示します。
string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');
名前 |
説明 |
Authorization |
ベアラー {token}。 必須です。
認証と承認の詳細については、こちらをご覧ください。 |
要求本文
要求本文で、次のパラメーターを含む JSON オブジェクトを指定します。
{
"recipients": [
{ "@odata.type": "microsoft.graph.driveRecipient" }
],
"roles": [ "read | write"]
}
パラメーター |
型 |
説明 |
Recipients |
Collection(driveRecipient) |
アクセス権を受け取る受信者のコレクション。 |
roles |
Collection(String) |
リンクが "既存のアクセス" リンクである場合は、ユーザーに付与するロールを指定します。 それ以外の場合は、リンクのロールと一致する必要があります。 |
使用可能なロールの一覧については、「 roles プロパティの値」を参照してください。
応答
成功した場合、このメソッドは 200 OK
応答コードと応答本文の アクセス許可 コレクションを返します。
更新されたリンクを表す アクセス許可 は、成功すると常に結果セットに返されます。 更新されたリンクは、'scope' プロパティを含む 'link' ファセットが存在することで識別できます。 場合によっては、更新されたリンクに元のリンクとは異なる URL が含まれている可能性があります。その場合は、新しい URL を使用する必要があります。
エラーがどのように返されるかについては、「エラー応答」のトピックを参照してください。
例
この例では、リンクに対する他の既存のアクセス許可を変更せずに、ユーザー john@contoso.comryan@external.com に共有リンクへのアクセスを許可します。
要求
POST https://graph.microsoft.com/v1.0/shares/{encoded-sharing-url}/permission/grant
Content-type: application/json
{
"recipients": [
{
"email": "john@contoso.com"
},
{
"email": "ryan@external.com"
}
],
"roles": ["read"]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Shares.Item.Permission.Grant;
using Microsoft.Graph.Models;
var requestBody = new GrantPostRequestBody
{
Recipients = new List<DriveRecipient>
{
new DriveRecipient
{
Email = "john@contoso.com",
},
new DriveRecipient
{
Email = "ryan@external.com",
},
},
Roles = new List<string>
{
"read",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Shares["{sharedDriveItem-id}"].Permission.Grant.PostAsGrantPostResponseAsync(requestBody);
プロジェクトに SDK を追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
mgc shares permission grant post --shared-drive-item-id {sharedDriveItem-id} --body '{\
"recipients": [\
{\
"email": "john@contoso.com"\
},\
{\
"email": "ryan@external.com"\
}\
],\
"roles": ["read"]\
}\
'
プロジェクトに 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"
graphshares "github.com/microsoftgraph/msgraph-sdk-go/shares"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphshares.NewGrantPostRequestBody()
driveRecipient := graphmodels.NewDriveRecipient()
email := "john@contoso.com"
driveRecipient.SetEmail(&email)
driveRecipient1 := graphmodels.NewDriveRecipient()
email := "ryan@external.com"
driveRecipient1.SetEmail(&email)
recipients := []graphmodels.DriveRecipientable {
driveRecipient,
driveRecipient1,
}
requestBody.SetRecipients(recipients)
roles := []string {
"read",
}
requestBody.SetRoles(roles)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
grant, err := graphClient.Shares().BySharedDriveItemId("sharedDriveItem-id").Permission().Grant().PostAsGrantPostResponse(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);
com.microsoft.graph.shares.item.permission.grant.GrantPostRequestBody grantPostRequestBody = new com.microsoft.graph.shares.item.permission.grant.GrantPostRequestBody();
LinkedList<DriveRecipient> recipients = new LinkedList<DriveRecipient>();
DriveRecipient driveRecipient = new DriveRecipient();
driveRecipient.setEmail("john@contoso.com");
recipients.add(driveRecipient);
DriveRecipient driveRecipient1 = new DriveRecipient();
driveRecipient1.setEmail("ryan@external.com");
recipients.add(driveRecipient1);
grantPostRequestBody.setRecipients(recipients);
LinkedList<String> roles = new LinkedList<String>();
roles.add("read");
grantPostRequestBody.setRoles(roles);
var result = graphClient.shares().bySharedDriveItemId("{sharedDriveItem-id}").permission().grant().post(grantPostRequestBody);
プロジェクトに SDK を追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
const options = {
authProvider,
};
const client = Client.init(options);
const permission = {
recipients: [
{
email: 'john@contoso.com'
},
{
email: 'ryan@external.com'
}
],
roles: ['read']
};
await client.api('/shares/{encoded-sharing-url}/permission/grant')
.post(permission);
プロジェクトに SDK を追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Shares\Item\Permission\Grant\GrantPostRequestBody;
use Microsoft\Graph\Generated\Models\DriveRecipient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new GrantPostRequestBody();
$recipientsDriveRecipient1 = new DriveRecipient();
$recipientsDriveRecipient1->setEmail('john@contoso.com');
$recipientsArray []= $recipientsDriveRecipient1;
$recipientsDriveRecipient2 = new DriveRecipient();
$recipientsDriveRecipient2->setEmail('ryan@external.com');
$recipientsArray []= $recipientsDriveRecipient2;
$requestBody->setRecipients($recipientsArray);
$requestBody->setRoles(['read', ]);
$result = $graphServiceClient->shares()->bySharedDriveItemId('sharedDriveItem-id')->permission()->grant()->post($requestBody)->wait();
プロジェクトに SDK を追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
Import-Module Microsoft.Graph.Files
$params = @{
recipients = @(
@{
email = "john@contoso.com"
}
@{
email = "ryan@external.com"
}
)
roles = @(
"read"
)
}
Grant-MgSharePermission -SharedDriveItemId $sharedDriveItemId -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.shares.item.permission.grant.grant_post_request_body import GrantPostRequestBody
from msgraph.generated.models.drive_recipient import DriveRecipient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = GrantPostRequestBody(
recipients = [
DriveRecipient(
email = "john@contoso.com",
),
DriveRecipient(
email = "ryan@external.com",
),
],
roles = [
"read",
],
)
result = await graph_client.shares.by_shared_drive_item_id('sharedDriveItem-id').permission.grant.post(request_body)
プロジェクトに SDK を追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
応答
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"hasPassword": false,
"id": "5fab944a-47ec-48d0-a9b5-5178a926d00f",
"link": {
"preventsDownload": false,
"scope": "users",
"type": "view",
"webUrl": "https://contoso.sharepoint.com/:t:/g/design/EZexPoDjW4dMtKFUfAl6BK4BvIUuss52hLYzihBfx-PD6Q"
},
"roles": [
"read"
]
}
]
}
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。
リンクが 既存のアクセス リンクの場合、次を表す追加のアクセス許可が返されます。
- アクセス権が正常に付与された受信者を表すユーザータイプのアクセス許可。 これらは、 grantedTo プロパティが存在することで識別できます。
- アクセスを取得するために認識されない外部ユーザーに送信する必要がある招待を表すリンク型のアクセス許可。 これらは、 招待 ファセットの存在によって識別できます。 これらのエントリには招待 URL を含む リンク が含まれており、grantedToIdentities コレクションは、リンクを送信するユーザーを示します。
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"hasPassword": false,
"id": "00000000-0000-0000-0000-000000000000",
"link": {
"preventsDownload": false,
"scope": "existingAccess",
"type": "view",
"webUrl": "https://contoso.sharepoint.com/teams/design/shareddocs/Document.docx"
},
"roles": [
"read"
]
},
{
"grantedTo": {
"user": {
"displayName": "John Smith",
"email": "john@contoso.com",
"id": "47aecee2-d061-4730-8ecb-4c61360441ae"
}
},
"id": "aTowIy5mfG1lbWJlcnNoaXB8bGltaXRlZDJAa2xhbW9kYi5vbm1pY3Jvc29mdC5jb20",
"roles": [
"read"
]
},
{
"grantedToIdentities": [
{
"user": {
"email": "ryan@external.com"
}
}
],
"invitation": {
"signInRequired": true
},
"roles": [
"read"
],
"link": {
"type": "view",
"webUrl": "https://contoso.sharepoint.com/:t:/g/teams/design/EZexPoDjW4dMtKFUfAl6BK4Bw_F7gFH63O310A7lDtK0mQ"
}
}
]
}
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。