【问题标题】:How to get a working document preview link from MS Graph如何从 MS Graph 获取工作文档预览链接
【发布时间】:2019-01-24 08:52:26
【问题描述】:

我正在尝试通过 MS Graph 获取用户最近文档的预览链接。不幸的是,端点返回的链接不起作用。

要获取有关文件的信息,我首先调用GET https://graph.microsoft.com/beta/me/drive/recent。然后我从 parentReference 属性中复制 driveID 和文档的 id。

要获得预览链接,我使用端点POST https://graph.microsoft.com/beta/drives/<DriveID>/items/<DocumentID>/preview 这很好用。但是当我单击链接时,我收到错误“此项目可能不存在或不再可用”。该文档存在于 SharePoint 上,否则它不会出现在“最近的文档”下。网址如下所示:https://www.onedrive.com/embed?webUrl=xyz.sharepoint.com/sites/nameOfTheSite/docLibName&id=sites/nameOfTheSite/DocLibName&embed=xxx&authToken=xxx

我希望/preview 端点的响应应该返回一个有效的 url。是否需要在 O365 上进行一些配置?

非常感谢

【问题讨论】:

    标签: rest office365 microsoft-graph-api onedrive


    【解决方案1】:

    嵌入链接 (preview) 在您的示例中看起来有效,因为 id 参数指的是 容器(库):sites/nameOfTheSite/DocLibName。不支持,嵌入链接应该引用一个文件

    这个问题很可能是由于itemId

    https://graph.microsoft.com/beta/drives/<DriveID>/items/<DocumentID>/preview
                                                            ^^^^^^^^^^^^   
    

    在您的示例中,它似乎指的是库而不是文件。确保指定了正确的itemId

    例如,https://graph.microsoft.com/v1.0/me/drive/recent 端点返回以下负载:

    {
       "value" : {
           //another properties are omitted for a clarity
           //... 
           "remoteItem": {
               "id": "01ECKZLCWSR7F76B64KZFL7I3QGZVPJELU"
               //...   
                "parentReference": {
                    "driveId": "b!79yKq-2MdkSDnQ7_1Pf3FOkRyDCajpRIvqtA7UrsEO-vu3D_qkpaT50Y6CMcSmFv",
                    "driveType": "documentLibrary",
                    "id": "01ECKZLCV6Y2GOVW7725BZO354PWSELRRZ"
                },
           }
       }
    }
    

    在哪里

    • remoteItem.Id - 对应于文件的项目 ID
    • remoteItem.parentReference.driveId - 对应驱动器 ID

    不要与对应的remoteItem.parentReference.Id 混淆 到图书馆的项目ID

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 2015-04-21
      相关资源
      最近更新 更多