简体   繁体   中英

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. This includes notably the WebDavUrl and the Package Type.

I made sure to have a OneNote item shared with me and verified the correctness of the data over the 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"

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. However when I execute the snippet above the PackageType in "item" is always 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. 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.

_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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM