[英]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.