我想在 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/