.net 如何使用msGraph sdk获取DriveItem的活动列表

niwlg2el  于 2023-04-07  发布在  .NET
关注(0)|答案(3)|浏览(115)

我有一个DriveItem,它由User1通过graph调用检出

https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}?expand=activities

我有我的活动清单

{...
    "id": "01VMODTUDZVXS2MQJORNEYUTEPWOJ7VSB",
    ...
    "activities": [
        {
            "@sharePoint.localizedRelativeTime": "1|0|3|38",
            "action": {
                "checkin": {},
                "edit": {},
                "version": {
                    "newVersion": "3.0"
                }
            },
            "actor": {
                "user": {
                    "email": "xxx.onmicrosoft.com",
                    "displayName": "Administrator)",
                    "self": {},
                    "userPrincipalName": "csgdeveloper@csgdevelopment.onmicrosoft.com"
                }
            },
            "id": "oFlcWLu82kiAeJgJAAAAAA==",
            "times": {
                "recordedTime": "2022-11-02T10:16:45Z"
            }
        ...
        }
    ],
...
...
    "shared": {
        "scope": "users"
    }
}

如果我使用SDK for C#在我的项目中尝试相同的方法

var activities = await this.GraphServiceClient.Drives[driveId].Items[driveItemId]
        .Request()
        .Expand("activities")
        .GetAsync();

我得到一个异常,消息是:

解析OData Select and Expand失败:在类型“microsoft.graph. driveItem”上找不到名为“activities”的属性。

nle07wnf

nle07wnf1#

适用于API版本1.0

var queryOptions = new List<QueryOption>()
{
  new QueryOption("expand", "activities")
};

  var driveItem = await this.GraphServiceClient.Drives[XXXXX].Items[XXXXXX]
            .Request(queryOptions)
            .GetAsync();

驱动器项属性AdditionalData我有新的键/值项,其键为:活动和价值:项目活动集合
谢谢你

ghhkc1vu

ghhkc1vu2#

在使用$expand时出于某种原因

GET /drives/{drive-id}/items/{item-id}?$expand=activities

响应失败并显示消息
分析OData选择和扩展失败:在类型“microsoft.graph.driveItem”上找不到名为“activities”的属性
使用C# SDK时

var activities = await this.GraphServiceClient.Drives[driveId].Items[driveItemId]
        .Request()
        .Expand("activities")
        .GetAsync();

它将生成上面的查询$expand并失败。
仅使用expand而不使用$

GET /drives/{drive-id}/items/{item-id}?expand=activities

响应成功,上面的查询可以用C# SDK这样写

var queryOptions = new List<QueryOption>()
{
  new QueryOption("expand", "activities")
};

var driveItem = await this.GraphServiceClient.Drives[driveId].Items[driveItemId]
            .Request(queryOptions)
            .GetAsync();
t30tvxxf

t30tvxxf3#

var queryOptions = new List<QueryOption>()
          {
            new QueryOption("expand", "listitem")
          };
    
var driveItemsPage = await this.GraphServiceClient
.Drives[driveId]
.Items[driveItemId]
.Children
.Request(queryOptions)
.Select(x => new
{x.Id,
x.Publication,
x.Name,
x.Description,
x.Size,
x.WebUrl,
x.Folder,
x.File,
x.FileSystemInfo,
x.ListItem
})
.GetAsync();

driveItemsPage中的每个项目都具有ListItem属性

var isCheckedOut = item.File != null 
? item.ListItem.Fields.AdditionalData.TryGetValue("CheckoutUserLookupId", out value) 
: false;

因此,如果项目已检出,则我将获得true

相关问题