c# - Microsoft Graph 列出 OneDrive 项目

标签 c# microsoft-graph-api

我想在 UWP 应用程序中列出我的所有 OneDrive for Business 项目。为此,我使用 NuGet 中的“Microsoft Graph 客户端库”。它是 Microsoft Graph REST-API 的包装器库。

当我尝试从我的根驱动器或特定文件夹 ID 获取所有项目或子项(我都尝试过)时,我只是得到一个空列表。但我的云端硬盘中有不同的文件和文件夹。即使我在没有此包装器的情况下使用 REST-API,我也只是得到一个空结果。

但是当我使用“最近”功能时,我会得到最近使用过的项目的列表。

// Returns an empty result without error
GraphServiceClient.Me.Drive.Items.Request().GetAsync()
GraphServiceClient.Me.Drive.Root.Children.Request().GetAsync()
GraphServiceClient.Drives["id"].Items.Request().GetAsync()

// Returns all my recent used items
GraphServiceClient.Me.Drive.Recent().Request().GetAsync()
GraphServiceClient.Drives["id"].Recent().Request().GetAsync()

HTTP 流量如下所示:

GET https://graph.microsoft.com/v1.0/me/drive/root/children HTTP/1.1
SdkVersion: graph-dotnet-1.0.1
Cache-Control: no-store, no-cache
Authorization: Bearer 1234567890123456789
Host: graph.microsoft.com
Connection: Keep-Alive

// Response:

HTTP/1.1 200 OK
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
Server: Microsoft-IIS/8.5
request-id: 123456-7890123
client-request-id: 123456-7890123
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West Europe","Slice":"SliceB","ScaleUnit":"000","Host":"AGSFE_IN_3","ADSiteName":"AMS"}}
OData-Version: 4.0
Duration: 823.6454
X-Powered-By: ASP.NET
Date: Wed, 15 Jun 2016 06:56:29 GMT

8c
{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('123456-7890123-456789')/drive/root/children","value":[]}
0

(我已经删除了 ID,所以这不是问题)

有人可以帮忙吗?

最佳答案

要使用 Microsoft Graph 从 OneDrive 获取项目,我们需要向端点发出请求。直到我们调用“GetAsync”方法后,“Request”方法才发出真正的请求。

以下是获取默认驱动器的子项的示例:

var items = await graphserviceClient.Me.Drive.Root.Children.Request().GetAsync();

引用here有关此 SDK 的更多详细信息。

关于c# - Microsoft Graph 列出 OneDrive 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37786970/

相关文章:

c# - Unity C# 多个函数共享相同的行为?

C# iTextSharp 通过字节数组合并多个 pdf

c# - 在不同的 Entity Framework 模型中不能有相同的表名吗?

c# - 什么方式比较好 : make own wrapper for DbContext or use DbContext in Controller

office365 - 如何检索 eventMessage 的事件

c# - 无法通过引用转换、装箱转换、拆箱转换、包装转换或空类型转换将类型 'string' 转换为 'int?'

oauth-2.0 - 在 Microsoft Graph API 中,获得管理员同意的应用是否可以为与批准它的管理员不同的用户生成 token ?

java - 使用 Java 将代理设置添加到 Microsoft Graph 客户端

azure-active-directory - 无法在 microsoft graph API 上获取用户公司信息

azure - 从 Azure 应用服务轻松身份验证获取 Microsoft Graph 的 AccessToken