名前空間: microsoft.graph
shareId または共有の URL を使用して、共有 DriveItem または共有アイテムのコレクションにアクセスします。
この API で共有の URL を使用するには、アプリで URL を共有のトークンに変換する必要があります。
この 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 |
HTTP 要求
GET /shares/{shareIdOrEncodedSharingUrl}
パス パラメーター
| パラメーター名 |
値 |
説明 |
|
shareIdOrEncodedSharingUrl |
string |
必須です。 API によって返される共有トークン、または適切にエンコードされた共有 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('+','-');
| 名前 |
型 |
説明 |
|
Prefer |
string |
省略可能。 以下に記載されている prefer 値のいずれかに設定します。 |
| 名前 |
説明 |
| redeemSharingLink |
shareIdOrEncodedSharingUrl が共有リンクである場合は、呼び出し元にアイテムへの永続的なアクセス権を付与します |
| redeemSharingLinkIfNecessary |
redeemSharingLink と同じですが、この要求の期間中のみアクセスが許可されていることが保証されます |
redeemSharingLink は、ブラウザーの共有リンクに移動する呼び出し元と同等と見なす必要があります (共有ジェスチャを受け入れます)。一方、redeemSharingLinkIfNecessary は、リンクのメタデータを単にピークすることを意図しているシナリオを対象としています。
応答
成功した場合、このメソッドは 200 OK 応答コードと、応答本文で sharedDriveItem リソースを返します。
例
要求
次の例は、共有アイテムを取得する要求を示しています。
GET /shares/{shareIdOrEncodedSharingUrl}
// Code snippets are only available for the latest version. Current version is 5.x
// 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}"].GetAsync();
// 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"
//other-imports
)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
shares, err := graphClient.Shares().BySharedDriveItemId("sharedDriveItem-id").Get(context.Background(), nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
SharedDriveItem result = graphClient.shares().bySharedDriveItemId("{sharedDriveItem-id}").get();
const options = {
authProvider,
};
const client = Client.init(options);
let sharedDriveItem = await client.api('/shares/{shareIdOrEncodedSharingUrl}')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->shares()->bySharedDriveItemId('sharedDriveItem-id')->get()->wait();
Import-Module Microsoft.Graph.Beta.Files
Get-MgBetaShareSharedDriveItemSharedDriveItem -SharedDriveItemId $sharedDriveItemId
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
result = await graph_client.shares.by_shared_drive_item_id('sharedDriveItem-id').get()
応答
次の例は応答を示しています。
HTTP/1.1 200 OK
Content-type: application/json
{
"id": "B64397C8-07AE-43E4-920E-32BFB4331A5B",
"name": "contoso project.docx",
"owner": {
"user": {
"id": "98E88F1C-F8DC-47CC-A406-C090248B30E5",
"displayName": "Ryan Gregg"
}
}
}
共有アイテムに直接アクセスする
SharedDriveItem には便利な情報がいくつか含まれていますが、ほとんどのアプリでは共有 DriveItem に直接アクセスする必要があります。
SharedDriveItem リソースには、共有アイテムのスコープ内のコンテンツにアクセスできるルートとアイテムのリレーションシップが含まれています。
例 (単一ファイル)
要求
driveItem リレーションシップを要求することで、共有されている DriveItem が返されます。
GET /shares/{shareIdOrUrl}/driveItem
// Code snippets are only available for the latest version. Current version is 5.x
// 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}"].DriveItem.GetAsync();
// 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"
//other-imports
)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
driveItem, err := graphClient.Shares().BySharedDriveItemId("sharedDriveItem-id").DriveItem().Get(context.Background(), nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
DriveItem result = graphClient.shares().bySharedDriveItemId("{sharedDriveItem-id}").driveItem().get();
const options = {
authProvider,
};
const client = Client.init(options);
let driveItem = await client.api('/shares/{shareIdOrUrl}/driveItem')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->shares()->bySharedDriveItemId('sharedDriveItem-id')->driveItem()->get()->wait();
Import-Module Microsoft.Graph.Beta.Files
Get-MgBetaShareDriveItem -SharedDriveItemId $sharedDriveItemId
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
result = await graph_client.shares.by_shared_drive_item_id('sharedDriveItem-id').drive_item.get()
応答
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "9FFFDB3C-5B87-4062-9606-1B008CA88E44",
"name": "contoso project.docx",
"eTag": "2246BD2D-7811-4660-BD0F-1CF36133677B,1",
"file": {},
"size": 109112
}
例 (共有フォルダー)
要求
driveItem リレーションシップを要求して、children コレクションを展開することで、共有されている DriveItem が共有フォルダー内のファイルとともに返されます。
GET /shares/{shareIdOrUrl}/driveItem?$expand=children
// Code snippets are only available for the latest version. Current version is 5.x
// 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}"].DriveItem.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Expand = new string []{ "children" };
});
// 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"
graphshares "github.com/microsoftgraph/msgraph-beta-sdk-go/shares"
//other-imports
)
requestParameters := &graphshares.ItemDriveItemRequestBuilderGetQueryParameters{
Expand: [] string {"children"},
}
configuration := &graphshares.ItemDriveItemRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
driveItem, err := graphClient.Shares().BySharedDriveItemId("sharedDriveItem-id").DriveItem().Get(context.Background(), configuration)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
DriveItem result = graphClient.shares().bySharedDriveItemId("{sharedDriveItem-id}").driveItem().get(requestConfiguration -> {
requestConfiguration.queryParameters.expand = new String []{"children"};
});
const options = {
authProvider,
};
const client = Client.init(options);
let driveItem = await client.api('/shares/{shareIdOrUrl}/driveItem')
.version('beta')
.expand('children')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Shares\Item\DriveItem\DriveItemRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new DriveItemRequestBuilderGetRequestConfiguration();
$queryParameters = DriveItemRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->expand = ["children"];
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->shares()->bySharedDriveItemId('sharedDriveItem-id')->driveItem()->get($requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Files
Get-MgBetaShareDriveItem -SharedDriveItemId $sharedDriveItemId -ExpandProperty "children"
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.shares.item.drive_item.drive_item_request_builder import DriveItemRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
query_params = DriveItemRequestBuilder.DriveItemRequestBuilderGetQueryParameters(
expand = ["children"],
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.shares.by_shared_drive_item_id('sharedDriveItem-id').drive_item.get(request_configuration = request_configuration)
応答
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "9FFFDB3C-5B87-4062-9606-1B008CA88E44",
"name": "Contoso Project",
"eTag": "2246BD2D-7811-4660-BD0F-1CF36133677B,1",
"folder": {},
"size": 10911212,
"children": [
{
"id": "AFBBDD79-868E-452D-AD4D-24697D4A4044",
"name": "Propsoal.docx",
"file": {},
"size": 19001
},
{
"id": "A91FE90A-2F2C-4EE6-B412-C4FFBA3F71A6",
"name": "Update to Proposal.docx",
"file": {},
"size": 91001
}
]
}
エラー応答
エラーが返される方法の詳細については、 エラー応答 に関する記事を参照してください。
- OneDrive for Businessと SharePoint の場合、Share API では常に認証が必要であり、ユーザー コンテキストなしで匿名で共有されたコンテンツにアクセスするために使用することはできません。