简体   繁体   English

如何使用Microsoft Graph API正确获取与我共享的所有项目?

[英]How to correctly get all the items shared with me using Microsoft Graph API?

The Microsoft Graph API C# SDK seems to return null for some of the fields of items queried with the SharedWithMe request. 对于使用SharedWithMe请求查询的项目的某些字段,Microsoft Graph API C#SDK似乎返回null。 This includes notably the WebDavUrl and the Package Type. 这尤其包括WebDavUrl和Package Type。

I made sure to have a OneNote item shared with me and verified the correctness of the data over the Graph Explorer. 我确保与我共享一个OneNote项目,并通过Graph Explorer验证数据的正确性。 I also verified that the permissions of my application were set correctly as : "User.Read Notes.Read.All Sites.Read.All Files.Read.All" 我还验证了我的应用程序的权限设置正确为:“User.Read Notes.Read.All Sites.Read.All Files.Read.All”

var graphClient = MicrosoftGraphService.Instance.GraphProvider;
var driveItems = await graphClient.Me.Drive.SharedWithMe().Request().GetAsync();
foreach (var item in driveItems)
{
    if (item.Package.Type == "oneNote") {...}
}

When I queried the Graph API over the Graph Explorer ( https://developer.microsoft.com/en-us/graph/graph-explorer ) with the equivalent GET: https://graph.microsoft.com/v1.0/me/drive/sharedWithMe it showed me all the items that are currently shared with me and all information relating to them. 当我通过Graph Explorer( https://developer.microsoft.com/en-us/graph/graph-explorer )使用等效的GET查询Graph API时: https//graph.microsoft.com/v1.0/ me / drive / sharedWithMe它向我展示了当前与我共享的所有项目以及与它们相关的所有信息。 However when I execute the snippet above the PackageType in "item" is always null. 但是,当我执行上面的代码片段时,“item”中的PackageType始终为null。


Edit: https://docs.microsoft.com/en-us/graph/api/drive-sharedwithme?view=graph-rest-1.0&tabs=cs suggest querying for the item with remoteItem-driveId and remoteItem-id. 编辑: https ://docs.microsoft.com/en-us/graph/api/drive-sharedwithme?view=graph-rest-1.0&tabs=cs建议使用remoteItem-driveId和remoteItem-id查询项目。 I'll see were this will lead me. 我会看到这会引导我。

This is what I came up with after experimentation. 这是我在实验后想出来的。 You get the response as a JSON which in my case was sufficient enough to continue. 你得到的响应是一个JSON,在我的情况下足以继续。

_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Your AccessToken");
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var message = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me/drive/sharedWithMe");
var response = await graphClient.HttpProvider.SendAsync(message);
var json = await response.Content.ReadAsStringAsync();

Of course a working solution with the SDK would be more enjoyable. 当然,使用SDK的工作解决方案会更有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Microsoft Graph API 获取所有组的用户名? - How to get user names of all groups using Microsoft Graph API? 如何使用 Microsoft.Graph 与登录用户共享日历 - how to get calendars shared with logged in user using Microsoft.Graph "在 c# 中使用 Microsoft Graph API 获取所有电子邮件" - Get all email message using Microsoft Graph API in c# 如何使用 Microsoft Graph api 从 azure 活动目录中获取所有用户属性 - How to get all user attributes from azure active directory using Microsoft Graph api 如何获取用户的组名是使用 Microsoft Graph API 的成员? - How to get group names of the user is a member of using Microsoft Graph API? 如何使用 Microsoft Graph api 或类似的 API 获取联系人组 - how to get contact group using Microsoft Graph api or similier apis 如何从 /me/mailboxSettings/timeZone 返回的 Microsoft Graph API 的时区值中获取 UTC 偏移量? - How to get UTC offset from Microsoft Graph API's timezone value returned from /me/mailboxSettings/timeZone? Microsoft Graph API ASP.NET MVC 获取驱动器项目 - Microsoft Graph API ASP.NET MVC Get Drive Items 如何在 .net core 中使用 Microsoft Graph 访问共享邮箱 - How to access shared mailbox using Microsoft Graph in .net core Microsoft Graph API 不返回共享工作表的表格 - Microsoft Graph API returning no tables for shared worksheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM