共有の招待状を送信する
[アーティクル]
12/01/2021
2 人の共同作成者
この記事の内容
名前空間: microsoft.graph
driveItem の共有招待状 を送信します 。
共有の招待状は受信者にアクセス許可を提供します。また、任意で受信者に共有リンク 付きの電子メールを送信します。
アクセス許可
この API を呼び出すには、次のいずれかのアクセス許可が必要です。アクセス許可の選択方法などの詳細については、「アクセス許可 」を参照してください。
アクセス許可の種類
アクセス許可 (特権の小さいものから大きいものへ)
委任 (職場または学校のアカウント)
Files.ReadWrite、Files.ReadWrite.All、Sites.ReadWrite.All
委任 (個人用 Microsoft アカウント)
Files.ReadWrite、Files.ReadWrite.All
アプリケーション
Files.ReadWrite.All、Sites.ReadWrite.All
HTTP 要求
POST /drives/{drive-id}/items/{item-id}/invite
POST /groups/{group-id}/drive/items/{item-id}/invite
POST /me/drive/items/{item-id}/invite
POST /sites/{siteId}/drive/items/{itemId}/invite
POST /users/{userId}/drive/items/{itemId}/invite
要求本文
要求本文で、次のパラメーターを含む JSON オブジェクトを指定します。
{
"requireSignIn": false,
"sendInvitation": false,
"roles": [ "read | write"],
"recipients": [
{ "@odata.type": "microsoft.graph.driveRecipient" },
{ "@odata.type": "microsoft.graph.driveRecipient" }
],
"message": "string"
}
パラメーター
種類
説明
Recipients
Collection(DriveRecipient )
アクセスおよび共有の招待状を受信する、受信者のコレクション。
message
String
共有の招待状に含まれるプレーンテキスト形式のメッセージ。最大の長さは 2000 文字です。
requireSignIn
Boolean
共有アイテムを表示するために、招待状の受信者がサインインする必要があるかどうかを指定します。
sendInvitation
Boolean
True の場合、 共有リンク が受信者に送信されます。 それ以外の場合は、通知を送信せずに直接アクセス許可が付与されます。
roles
Collection(String)
共有の招待状の受信者に付与されるロールを指定します。
expirationDateTime
DateTimeOffset
アクセス許可の有効期限が切れる DateTime を指定します。 アカウント、OneDrive for Business、SharePointプレミアム個人アカウントでOneDriveできます。
パスワード
String
作成者が招待に設定したパスワード。 オプションとOneDrive個人用のみです。
例
この例では、"ryan@contoso.com" というメール アドレスを持つユーザーに共有の招待状を、共同作業中のファイルについてのメッセージと共に送信します。この招待により、Ryan にはファイルへの読み取り/書き込みアクセス権が付与されます。
HTTP 要求
成功した場合、このメソッドは 200 OK 応答コードと、応答本文でアクセス許可 コレクション オブジェクトを返します。
POST /me/drive/items/{item-id}/invite
Content-type: application/json
{
"recipients": [
{
"email": "ryan@contoso.com"
}
],
"message": "Here's the file that we're collaborating on.",
"requireSignIn": true,
"sendInvitation": true,
"roles": [ "write" ],
"password": "password123",
"expirationDateTime": "2018-07-15T14:00:00.000Z"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var recipients = new List<DriveRecipient>()
{
new DriveRecipient
{
Email = "ryan@contoso.com"
}
};
var message = "Here's the file that we're collaborating on.";
var requireSignIn = true;
var sendInvitation = true;
var roles = new List<String>()
{
"write"
};
var password = "password123";
var expirationDateTime = "2018-07-15T14:00:00Z";
await graphClient.Me.Drive.Items["{driveItem-id}"]
.Invite(recipients,requireSignIn,roles,sendInvitation,message,null,expirationDateTime,password)
.Request()
.PostAsync();
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
const options = {
authProvider,
};
const client = Client.init(options);
const permission = {
recipients: [
{
email: 'ryan@contoso.com'
}
],
message: 'Here\'s the file that we\'re collaborating on.',
requireSignIn: true,
sendInvitation: true,
roles: [ 'write' ],
password: 'password123',
expirationDateTime: '2018-07-15T14:00:00.000Z'
};
await client.api('/me/drive/items/{item-id}/invite')
.post(permission);
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/drive/items/{item-id}/invite"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
NSMutableArray *recipientsList = [[NSMutableArray alloc] init];
MSGraphDriveRecipient *recipients = [[MSGraphDriveRecipient alloc] init];
[recipients setEmail:@"ryan@contoso.com"];
[recipientsList addObject: recipients];
payloadDictionary[@"recipients"] = recipientsList;
NSString *message = @"Here's the file that we're collaborating on.";
payloadDictionary[@"message"] = message;
BOOL requireSignIn = YES;
payloadDictionary[@"requireSignIn"] = requireSignIn;
BOOL sendInvitation = YES;
payloadDictionary[@"sendInvitation"] = sendInvitation;
NSMutableArray *rolesList = [[NSMutableArray alloc] init];
[rolesList addObject: @"write"];
payloadDictionary[@"roles"] = rolesList;
NSString *password = @"password123";
payloadDictionary[@"password"] = password;
NSString *expirationDateTimeDateTimeString = @"07/15/2018 14:00:00";
NSDate *expirationDateTime = [NSDate ms_dateFromString: expirationDateTimeDateTimeString];
payloadDictionary[@"expirationDateTime"] = expirationDateTime;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<DriveRecipient> recipientsList = new LinkedList<DriveRecipient>();
DriveRecipient recipients = new DriveRecipient();
recipients.email = "ryan@contoso.com";
recipientsList.add(recipients);
String message = "Here's the file that we're collaborating on.";
Boolean requireSignIn = true;
Boolean sendInvitation = true;
LinkedList<String> rolesList = new LinkedList<String>();
rolesList.add("write");
String password = "password123";
String expirationDateTime = "07/15/2018 14:00:00";
graphClient.me().drive().items("{item-id}")
.invite(DriveItemInviteParameterSet
.newBuilder()
.withRequireSignIn(requireSignIn)
.withRoles(rolesList)
.withSendInvitation(sendInvitation)
.withMessage(message)
.withRecipients(recipientsList)
.withRetainInheritedPermissions(null)
.withExpirationDateTime(expirationDateTime)
.withPassword(password)
.build())
.buildRequest()
.post();
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
応答
以下は、応答の例です。
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"@deprecated.GrantedTo": "GrantedTo has been deprecated. Refer to GrantedToV2",
"grantedTo": {
"user": {
"displayName": "Robin Danielsen",
"id": "42F177F1-22C0-4BE3-900D-4507125C5C20"
}
},
"grantedToV2": {
"user": {
"id": "42F177F1-22C0-4BE3-900D-4507125C5C20",
"displayName": "Robin Danielsen"
},
"siteUser": {
"id": "1",
"displayName": "Robin Danielsen",
"loginName": "Robin Danielsen"
}
},
"hasPassword": true,
"id": "CCFC7CA3-7A19-4D57-8CEF-149DB9DDFA62",
"invitation": {
"email": "robin@contoso.com",
"signInRequired": true
},
"roles": [ "write" ],
"expirationDateTime": "2018-07-15T14:00:00.000Z"
}
]
}
personal (OneDrive 個人用) の driveType を持つ ドライブ は、ルートの DriveItem でアクセス許可を作成したり、変更したりすることはできません。
使用可能な役割の一覧については、「roles プロパティの 値」を参照してください 。
エラー応答
エラーがどのような形で返されるかについては、「エラー応答 」を参照してください。