如何显示ms graph(搜索结果)driveitem文件的路径(文件夹)?

ccrfmcuu  于 2021-06-27  发布在  Java
关注(0)|答案(2)|浏览(436)

我在msgraph中有以下(基于kotlin/java)查询

var driveItemSearchCollectionRequestBuilder =
    safeGraphServiceClient
        .sites(SHAREPOINT_SITE_ID)
        .drive()
        .root()
        .search("¤A=118628")

do{

    driveItemSearchCollectionPage = driveItemSearchCollectionRequestBuilder?.buildRequest()?.get()?:break

    driveItemSearchCollectionPage.currentPage.map {driveItem->
        driveItem?.let{ safeDriveItem ->

           //Here I need to find my `safeDriveItem`'s (which is a file) path (where the file is stored)... (or folder)
           //`safeDriveItem.folder` is null... (since this is a file)
        }
    }
    driveItemSearchCollectionRequestBuilder = driveItemCollectionPage.nextPage

}while(driveItemSearchCollectionRequestBuilder!=null)

从而生成一组(页)driveitems。此搜索可以在我的sharepoint树中的任何文件夹中找到该文件。在哪里(或如何)可以找到drivitem文件的文件夹(即“\myfolder\level1\level2\level3”)(文件夹项为 null 对于这里的driveitem,我没有找到任何包含它的值)。或者我需要做一些“聪明”的回溯?

mftmpeh8

mftmpeh81#

@shiva找到了一个解决方案,我现在可以像这样查询文件的路径:

var driveItemSearchCollectionRequestBuilder =
    safeGraphServiceClient
        .sites(SHAREPOINT_SITE_ID)
        .drive()
        .root()
        .search("¤A=118628")

do{

    driveItemSearchCollectionPage = driveItemSearchCollectionRequestBuilder?.buildRequest()?.get()?:break

    driveItemSearchCollectionPage.currentPage.map {driveItem->
        driveItem?.let{ safeDriveItem ->

           val pathItem =  safeGraphServiceClient
               .sites(SHAREPOINT_SITE_ID)
               .drive()
               .items(safeDriveItem.id)
               .buildRequest()
               .get()

           val path = pathItem.parentReference.path 

           galleryItems.add(path, driveItem.name) //My functiomn adds now path and file to db 

        }
    }
    driveItemSearchCollectionRequestBuilder = driveItemCollectionPage.nextPage

}while(driveItemSearchCollectionRequestBuilder!=null)

我希望将来 driveItem.parentReference.path 可以填充,这样我们就可以避免对graph的二次调用,或者在搜索短语上设置一些开关来公开路径(通信成本Angular )。

ecbunoof

ecbunoof2#

当您使用上述代码搜索时,正如您所说,您将获得driveitems。选择要为其指定文件夹路径的driveitem的id,然后调用 https://graph.microsoft.com/v1.0/sites/{siteid}/drive/Items/{driveItemid} 它将拉取整个驱动器项对象,其中有一个parentreference对象,该对象内部具有path属性。
sharepoint有两个不同的数据源,在这两个数据源中,搜索将通过索引从一个源中提取数据,很少有属性不会显示。所以直接拉一个对象就得到了所有的属性。

相关问题