命名空间:microsoft.graph
警告
此终结点需要 TLS 1.2 正常运行。 Microsoft 宣布弃用 TLS 1.0 和 1.1,以Office 365和Azure AD服务。 尽管 Microsoft Graph仍支持这两种协议,但可能会遇到传输级别错误。 有关 TLS 1.0 和 1.1 弃用功能详细信息,请参阅在你的环境中启用 对 TLS 1.2 的支持。
使用此 API 检索特定格式的项的内容。 并非所有文件都可转换成全部格式。
若要下载原始格式的项目,请参阅下载项内容。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
Files.Read、Files.ReadWrite、Files.Read.All、Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
Files.Read、Files.ReadWrite、Files.Read.All、Files.ReadWrite.All |
| 应用程序 |
Files.Read.All、Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All |
HTTP 请求
GET /drive/items/{item-id}/content?format={format}
GET /drive/root:/{path and filename}:/content?format={format}
查询参数
| 参数 |
类型 |
说明 |
| format |
string |
指定应以何种格式下载项内容。 |
以下值对于 format 参数有效:
| 格式值 |
说明 |
支持的源扩展名 |
| pdf |
将项转换成 PDF 格式。 |
csv、doc、docx、odp、ods、odt、pot、potm、potx、pps、ppsx、ppsxm、ppt、pptm、pptx、rtf、xls、xlsx |
| 名称 |
值 |
说明 |
| if-none-match |
String |
如果包含此请求标头,且提供的 eTag(或 cTag)与文件中的当前标记不匹配,则返回 HTTP 304 Not Modified 响应。 |
示例
GET /me/drive/items/{item-id}/content?format={format}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("format", "{format}")
};
var stream = await graphClient.Me.Drive.Items["{driveItem-id}"].Content
.Request( queryOptions )
.GetAsync();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
let stream = await client.api('/me/drive/items/{item-id}/content?format=%7Bformat%7D')
.get();
有关如何将 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}/content?format=%7Bformat%7D"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphStream *stream = [[MSGraphStream alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new QueryOption("format", "{format}"));
InputStream stream = graphClient.customRequest("/me/drive/items/{item-id}/content", InputStream.class)
.buildRequest( requestOptions )
.get();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
响应
返回 302 Found 响应,重定向到已转换文件的已预先验证的下载 URL。
应用必须遵循响应中的 Location 头,才能下载已转换的文件。
已预先验证的 URL 仅在短期(几分钟)内有效,无需 Authorization 头即可访问。
HTTP/1.1 302 Found
Location: https://b0mpua-by3301.files.1drv.com/y23vmagahszhxzlcvhasdhasghasodfi
错误响应
请参阅错误响应,详细了解错误返回方式。