名前空間: microsoft.graph
重要
Microsoft Graph の /beta バージョンの API は変更される可能性があります。 実稼働アプリケーションでこれらの API を使用することは、サポートされていません。 v1.0 で API を使用できるかどうかを確認するには、Version セレクターを使用します。
driveItem driveItem を共有するリンクを作成します。
createLink アクションは、呼び出し元のアプリケーションに指定されたリンクの種類がまだ存在しない場合に、新しい共有リンクを作成します。
指定した種類の共有リンクがアプリに既に存在する場合は、既存の共有リンクが返されます。
DriveItem リソースは、そのリソースの先祖から共有アクセス許可を継承します。
この API は、次の国内クラウド展開で使用できます。
| グローバル サービス |
米国政府機関 L4 |
米国政府機関 L5 (DOD) |
21Vianet が運営する中国 |
| ✅ |
✅ |
✅ |
✅ |
アクセス許可
この API の最小特権としてマークされているアクセス許可またはアクセス許可を選択します。
アプリで必要な場合にのみ、より高い特権のアクセス許可またはアクセス許可を使用します。 委任されたアクセス許可とアプリケーションのアクセス許可の詳細については、「アクセス許可の種類」を参照してください。 これらのアクセス許可の詳細については、「アクセス許可のリファレンス」を参照してください。
| アクセス許可の種類 |
最小特権アクセス許可 |
より高い特権のアクセス許可 |
| 委任 (職場または学校のアカウント) |
Files.ReadWrite |
Files.ReadWrite.All、Sites.ReadWrite.All |
| 委任 (個人用 Microsoft アカウント) |
Files.ReadWrite |
Files.ReadWrite.All |
| アプリケーション |
Files.ReadWrite.All |
Sites.ReadWrite.All |
注:
SharePoint Embedded には、コンテナーのコンテンツにアクセスするための FileStorageContainer.Selected アクセス許可が必要です。 このアクセス許可は、前に説明した権限とは異なります。 Microsoft Graph のアクセス許可に加えて、アプリには、この API を呼び出すために必要な コンテナーの種類のアクセス許可 が必要です。 詳細については、「 SharePoint Embedded の認証と承認」を参照してください。
HTTP 要求
POST /drives/{driveId}/items/{itemId}/createLink
POST /groups/{groupId}/drive/items/{itemId}/createLink
POST /me/drive/items/{itemId}/createLink
POST /sites/{siteId}/drive/items/{itemId}/createLink
POST /users/{userId}/drive/items/{itemId}/createLink
| 名前 |
説明 |
| Authorization |
ベアラー {token}。 必須です。
認証と認可についての詳細をご覧ください。 |
| Content-Type |
application/json. 必須です。 |
要求本文
要求本文はアプリケーションが要求する共有リンクのプロパティを定義します。
要求は、次のプロパティを含む JSON オブジェクトである必要があります。
| プロパティ |
型 |
説明 |
| type |
String |
省略可能。 作成する共有リンクの種類。 |
| scope |
String |
省略可能。 作成するリンクのスコープ。
anonymous、organization、またはusers |
| expirationDateTime |
DateTimeOffset |
省略可能。 DateTime の形式が yyyy-MM-ddTHH:mm:ssZ の文字列は、アクセス許可の有効期限を示します。 |
| パスワード |
String |
省略可能。 作成者は、共有リンクのパスワードを設定します。 |
| Recipients |
driveRecipient コレクション |
省略可能。 共有リンクへのアクセスを受け取る受信者のコレクション。 |
| retainInheritedPermissions |
ブール値 |
省略可能。
true (既定値) の場合、このアイテムを初めて共有するときに、既存の継承されたアクセス許可が共有アイテムに保持されます。
false場合、共有時に既存のすべてのアクセス許可が初めて削除されます。 |
| sendNotification |
ブール値 |
true場合、このメソッドは、recipientsで指定されたユーザーに電子メールの共有リンクを送信します。 OneDrive for Businessまたは SharePoint に適用されます。 既定値は false です。 省略可能。 |
リンクの種類
type パラメーターには次の値を使用できます。
| 種類の値 |
説明 |
| view |
driveItem への読み取り専用リンクを作成します。 |
| 復習 |
driveItem へのレビュー リンクを作成します。 このオプションは、OneDrive for Businessおよび SharePoint 内のファイルでのみ使用できます。 |
| edit |
driveItem への読み取り/書き込みリンクを作成します。 |
| 埋め込み |
driveItem への埋め込み可能なリンクを作成します。 |
| blocksDownload |
driveItem へのダウンロードをブロックする読み取り専用リンクを作成します。 このオプションは、OneDrive for Businessおよび SharePoint 内のファイルでのみ使用できます。 |
| createOnly |
driveItem へのアップロード専用リンクを作成します。 このオプションは、OneDrive for Businessおよび SharePoint 内のフォルダーでのみ使用できます。 |
| addressBar |
新しく作成されたファイルのブラウザー アドレス バーに表示される既定のリンクを作成します。 OneDrive for Business および SharePoint の場合のみ使用できます。 organization管理者は、このリンクの種類がサポートされているかどうかを構成し、サポートする機能を指定します。 |
| adminDefault |
organizationの管理者によって決定された driveItem への既定のリンクを作成します。 OneDrive for Business および SharePoint の場合のみ使用できます。 管理者は、organizationのポリシーを適用します。 |
スコープの種類
scope パラメーターには次の値を使用できます。
| 値 |
説明 |
| アノニマス |
リンクを知っているすべてのユーザーは、サインインするこなくアクセスできます。 organization外のユーザーが含まれる場合があります。 管理者は、匿名リンクのサポートを無効にすることができます。 |
| 組織 |
組織 (テナント) にサインインしているユーザーは、リンクを使用してアクセスできます。 OneDrive for Business および SharePoint の場合のみ使用できます。 |
| users |
受信者のコレクション内の特定のユーザーは、リンクを使用してアクセスを取得できます。 OneDrive for Business および SharePoint の場合のみ使用できます。 |
応答
正常に実行されると、このメソッドは要求された共有アクセス許可を表す応答本文で、単一のアクセス許可リソースを返します。
応答は、driveItem 用に新しい共有リンクが作成された場合は201 Created、既存のリンクが返された場合は200 OKされます。
例
例 1: 匿名共有リンクを作成する
次の例では、ユーザーの OneDrive で {itemId} によって指定された driveItem の共有リンクを作成するように要求します。
共有リンクは、読み取り専用でそのリンクによってだれでも使用可能になるよう構成されます。
OneDrive for Businessおよび SharePoint ユーザーの場合は、sendNotification パラメーターを使用して共有リンクを作成します。 その後、共有リンクが電子メールで受信者に送信されます。
retainInheritedPermissionsが false の場合、共有を初めて行うと、既存のすべてのアクセス許可が削除されます。
要求
POST https://graph.microsoft.com/beta/me/drive/items/{itemId}/createLink
Content-Type: application/json
{
"type": "view",
"scope": "anonymous",
"password": "String",
"recipients": [
{
"@odata.type": "microsoft.graph.driveRecipient"
}
],
"sendNotification": true,
"retainInheritedPermissions": false
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.CreateLink;
using Microsoft.Graph.Beta.Models;
var requestBody = new CreateLinkPostRequestBody
{
Type = "view",
Scope = "anonymous",
Password = "String",
Recipients = new List<DriveRecipient>
{
new DriveRecipient
{
OdataType = "microsoft.graph.driveRecipient",
},
},
SendNotification = true,
RetainInheritedPermissions = false,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].CreateLink.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphdrives.NewCreateLinkPostRequestBody()
type := "view"
requestBody.SetType(&type)
scope := "anonymous"
requestBody.SetScope(&scope)
password := "String"
requestBody.SetPassword(&password)
driveRecipient := graphmodels.NewDriveRecipient()
recipients := []graphmodels.DriveRecipientable {
driveRecipient,
}
requestBody.SetRecipients(recipients)
sendNotification := true
requestBody.SetSendNotification(&sendNotification)
retainInheritedPermissions := false
requestBody.SetRetainInheritedPermissions(&retainInheritedPermissions)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
createLink, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").CreateLink().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.createlink.CreateLinkPostRequestBody createLinkPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.createlink.CreateLinkPostRequestBody();
createLinkPostRequestBody.setType("view");
createLinkPostRequestBody.setScope("anonymous");
createLinkPostRequestBody.setPassword("String");
LinkedList<DriveRecipient> recipients = new LinkedList<DriveRecipient>();
DriveRecipient driveRecipient = new DriveRecipient();
driveRecipient.setOdataType("microsoft.graph.driveRecipient");
recipients.add(driveRecipient);
createLinkPostRequestBody.setRecipients(recipients);
createLinkPostRequestBody.setSendNotification(true);
createLinkPostRequestBody.setRetainInheritedPermissions(false);
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").createLink().post(createLinkPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const permission = {
type: 'view',
scope: 'anonymous',
password: 'String',
recipients: [
{
'@odata.type': 'microsoft.graph.driveRecipient'
}
],
sendNotification: true,
retainInheritedPermissions: false
};
await client.api('/me/drive/items/{itemId}/createLink')
.version('beta')
.post(permission);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\CreateLink\CreateLinkPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\DriveRecipient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CreateLinkPostRequestBody();
$requestBody->setType('view');
$requestBody->setScope('anonymous');
$requestBody->setPassword('String');
$recipientsDriveRecipient1 = new DriveRecipient();
$recipientsDriveRecipient1->setOdataType('microsoft.graph.driveRecipient');
$recipientsArray []= $recipientsDriveRecipient1;
$requestBody->setRecipients($recipientsArray);
$requestBody->setSendNotification(true);
$requestBody->setRetainInheritedPermissions(false);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->createLink()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
type = "view"
scope = "anonymous"
password = "String"
recipients = @(
@{
"@odata.type" = "microsoft.graph.driveRecipient"
}
)
sendNotification = $true
retainInheritedPermissions = $false
}
New-MgBetaDriveItemLink -DriveId $driveId -DriveItemId $driveItemId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.drives.item.items.item.create_link.create_link_post_request_body import CreateLinkPostRequestBody
from msgraph_beta.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 = CreateLinkPostRequestBody(
type = "view",
scope = "anonymous",
password = "String",
recipients = [
DriveRecipient(
odata_type = "microsoft.graph.driveRecipient",
),
],
send_notification = True,
retain_inherited_permissions = False,
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').create_link.post(request_body)
応答
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": "123ABC",
"roles": ["write"],
"link": {
"type": "view",
"scope": "anonymous",
"webUrl": "https://1drv.ms/A6913278E564460AA616C71B28AD6EB6",
"application": {
"id": "1234",
"displayName": "Sample Application"
},
},
"hasPassword": true
}
例 2: 会社の共有可能なリンクを作成する
OneDrive for Business および SharePoint は、会社の共有可能リンクをサポートしています。
匿名リンクに似ていますが、所有するorganizationのメンバーに対してのみ機能します。
会社の共有可能リンクを作成するには、scope パラメーターで値 organization を指定して使用します。
要求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/createLink
Content-Type: application/json
{
"type": "edit",
"scope": "organization"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.CreateLink;
var requestBody = new CreateLinkPostRequestBody
{
Type = "edit",
Scope = "organization",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].CreateLink.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
//other-imports
)
requestBody := graphdrives.NewCreateLinkPostRequestBody()
type := "edit"
requestBody.SetType(&type)
scope := "organization"
requestBody.SetScope(&scope)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
createLink, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").CreateLink().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.createlink.CreateLinkPostRequestBody createLinkPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.createlink.CreateLinkPostRequestBody();
createLinkPostRequestBody.setType("edit");
createLinkPostRequestBody.setScope("organization");
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").createLink().post(createLinkPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const permission = {
type: 'edit',
scope: 'organization'
};
await client.api('/me/drive/items/{item-id}/createLink')
.version('beta')
.post(permission);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\CreateLink\CreateLinkPostRequestBody;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CreateLinkPostRequestBody();
$requestBody->setType('edit');
$requestBody->setScope('organization');
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->createLink()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
type = "edit"
scope = "organization"
}
New-MgBetaDriveItemLink -DriveId $driveId -DriveItemId $driveItemId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.drives.item.items.item.create_link.create_link_post_request_body import CreateLinkPostRequestBody
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = CreateLinkPostRequestBody(
type = "edit",
scope = "organization",
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').create_link.post(request_body)
応答
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": "123ABC",
"roles": ["write"],
"link": {
"type": "edit",
"scope": "organization",
"webUrl": "https://contoso-my.sharepoint.com/personal/ellen_contoso_com/...",
"application": {
"id": "1234",
"displayName": "Sample Application"
},
}
}
例 3: 埋め込み可能なリンクの作成
リンクの種類で embed を使用する場合、返される webUrl は <iframe> HTML 要素に埋め込むことができます。
埋め込みリンクが作成されると、 webHtml プロパティには、コンテンツをホストする <iframe> の HTML コードが含まれます。
注: 埋め込みリンクは、OneDrive 個人用でのみサポートされます。
要求
次の例は要求を示しています。
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/createLink
Content-Type: application/json
{
"type": "embed"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.CreateLink;
var requestBody = new CreateLinkPostRequestBody
{
Type = "embed",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].CreateLink.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
//other-imports
)
requestBody := graphdrives.NewCreateLinkPostRequestBody()
type := "embed"
requestBody.SetType(&type)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
createLink, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").CreateLink().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.createlink.CreateLinkPostRequestBody createLinkPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.createlink.CreateLinkPostRequestBody();
createLinkPostRequestBody.setType("embed");
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").createLink().post(createLinkPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const permission = {
type: 'embed'
};
await client.api('/me/drive/items/{item-id}/createLink')
.version('beta')
.post(permission);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\CreateLink\CreateLinkPostRequestBody;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CreateLinkPostRequestBody();
$requestBody->setType('embed');
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->createLink()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
type = "embed"
}
New-MgBetaDriveItemLink -DriveId $driveId -DriveItemId $driveItemId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.drives.item.items.item.create_link.create_link_post_request_body import CreateLinkPostRequestBody
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = CreateLinkPostRequestBody(
type = "embed",
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').create_link.post(request_body)
応答
次の例は要求を示しています。
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": "123ABC",
"roles": ["read"],
"link": {
"type": "embed",
"webHtml": "<IFRAME src=\"https://onedrive.live.com/...\"></IFRAME>",
"webUrl": "https://onedive.live.com/...",
"application": {
"id": "1234",
"displayName": "Sample Application"
},
}
}
- organizationの既定のポリシーと driveItem に対する呼び出し元のアクセス許可に基づいてリンクを作成するには、スコープと型パラメーターを省略します。
- このアクションを使用して作成されたリンクは、organizationに既定の有効期限ポリシーが適用されない限り有効期限が切れません。
- リンクは driveItem の共有アクセス許可に表示され、 driveItem の所有者が削除できます。
- リンクは、 driveItem がチェックアウトされていない限り、常に driveItem の現在のバージョンを指します (SharePoint のみ)。