【问题标题】:How do I reveal a MS Graph (search result) driveItem File's path (folder)?如何显示 MS Graph(搜索结果)driveItem 文件的路径(文件夹)?
【发布时间】:2021-01-05 17:32:00
【问题描述】:

我在 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)

这会产生一组(页面)驱动项。此搜索可以在我的共享点树的任何文件夹中找到该文件。我在哪里(或如何)可以找到 drivItem 文件的文件夹(即 '\MyFolder\Level1\Level2\Level3')? (这里的 driveItem 的文件夹项目是null,我还没有找到包含它的任何值)。还是我需要做一些“聪明”的回溯?

【问题讨论】:

  • 当您使用上述代码进行搜索时,正如您所说,您将获得 driveItems。选择您想要文件夹路径的 driveItem 的 id,然后调用 https://graph.microsoft.com/v1.0/sites/{siteid}/drive/Items/{driveItemid} 这将拉取整个驱动器项目对象,该对象具有 parentReferrence 内部具有路径属性的对象。
  • 它对你有用吗?
  • 其实,我现在只是去测试一下...给我一些咖啡杯...
  • 谢谢,测试了它,我可以从辅助查询中提取路径。为什么 MGraph 不在我的主要搜索请求中填充该值,或者我需要在搜索中添加一些参数?我会用你上面的建议来回答我的问题,quute 已经解决了。
  • 我将在您的后续问题中添加答案。请接受它:)-

标签: java android kotlin microsoft-graph-api


【解决方案1】:

当您使用上述代码进行搜索时,正如您所说,您将获得 driveItems。选择您想要文件夹路径的 driveItem 的 id,然后调用

https://graph.microsoft.com/v1.0/sites/{siteid}/drive/Items/{driveItemid}

这将拉动整个驱动器项目对象,该对象具有一个 parentReference 对象,该对象内部具有路径属性。

Sharepoint 有两个不同的数据源,其中搜索将通过从一个源建立索引来提取数据,并且可能不会显示一些属性。所以直接拉出一个对象会给你所有的属性。

【讨论】:

    【解决方案2】:

    @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 的二次调用,或者在搜索短语上设置一些开关来公开路径(从通信成本的角度来看)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-05
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      • 2012-06-17
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      相关资源
      最近更新 更多