如何使用 MS Graph 从 driveItem 中查找 OneNote Notebook 对象? [英] how to find OneNote Notebook object from driveItem with MS Graph?

查看:138
本文介绍了如何使用 MS Graph 从 driveItem 中查找 OneNote Notebook 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 OneDrive 中创建 OneNote 笔记本时,Microsoft 会显示一个 DriveItem,其中包含一个包方面和 oneNotetype.这正是根据文档.driveItem 似乎是实际 Notebook 的链接/引用 - 存储在隐藏"文件夹中.

When a OneNote Notebook is created in OneDrive, Microsoft shows a DriveItem with a package facet and type of oneNote. This is exactly per documentation. The driveItem appears to be a link/reference to the actual Notebook - which is stored in a "hidden" folder.

还有 Graph API 可以获取所有用户的 OneNote Notebook 的列表,您可以通过它的 id 检索特定 Notebook.但是,笔记本的 id 与其 driveItem 不同.

There are also Graph APIs to get a list of all the user's OneNote Notebooks, and you can retrieve a specific Notebook by it's id. The Notebook's id, however, is not the same as it's driveItem.

给定一个带有 OneNote 包面的 driveItem,我如何获取实际 Notebook 的 id 以便检索它及其详细信息?

Given a driveItem with a OneNote package facet, how do I get the id of the actual Notebook so I can retrieve it and its details?

我使用 Graph Explorer 进行了非常彻底的调查,但没有成功.我不敢相信这是真的,但是笔记本名称"是否必须是唯一的?这是我能看到的唯一与两个对象相关联的属性(所有者/用户权限除外).

I have investigated pretty-thoroughly using Graph Explorer without success. I can't believe it would be true, but are the Notebook "names" required to be unique? This is the only property I can see (other than owner/user-permissions) that would correlate across the two objects.

推荐答案

Notebook id 未通过 DriveItem 资源显示.它们由 API 返回,因此它准确地反映了 OneDrive UI 返回的相同文件,但它们并不意味着直接与之交互.要使用 Notebooks,您需要使用 Notes API.

The Notebook id isn't surfaced through the DriveItem resource. They're returned by the API so it acuratly reflect the same files returned by the OneDrive UI but they're not meant to be interacted with directly. For working with Notebooks, you need to use the Notes API.

OneDrive 文档更直接本主题:

注意:虽然 OneDrive 存储 OneNote 笔记本,但您不应使用 OneDrive API 来处理 OneNote 笔记本.

Working with OneNote Notebooks

Note: Although OneDrive stores OneNote notebooks, you shouldn't use the OneDrive API to work with OneNote notebooks.

此文档集还包括对 包资源类型.

目前没有一种简单的方法可以从对应的 DriveItem 中找出笔记本的 id.您可以使用一种技巧,但请注意,这不是记录的方法.

At the moment there isn't a simple method to uncover a Notebooks's id from it's corrisponsing DriveItem. There is one trick you can use, but fair warning, this is not a documented method.

  1. 使用 Graph Explorer(无需登录),执行以下调用:

  1. Using Graph Explorer (without loging in), execute the following call:

https://graph.microsoft.com/v1.0/me/drive/items/01BYE5RZ35EU76DRTYZ5DK5DATNBSRPLC7

  • 查看结果中的eTag:

    "eTag": "\"{E13F257D-78C6-46CF-AE8C-13686517AC5F},1\""
    

  • 现在使用以下方法查看笔记本列表:

  • Now take a gander at the list of Notebooks using:

    https://graph.microsoft.com/v1.0/me/onenote/notebooks
    

  • 返回的第一个 Notebook 具有以下 ID:

  • The first Notebook returned has the following id:

    "id": "1-e13f257d-78c6-46cf-ae8c-13686517ac5f",
    

  • 当您并排查看这些时,您会注意到 Notebook 的 id 包含与 eTag 相同的数据,尽管略有不同不同的顺序({digit}-{guid}):

  • When you look at these side-by-side, you'll notice the Notebook's id contains the same data as the eTag, albeit in a slightly different order ({digit}-{guid}):

    "eTag": "\"{E13F257D-78C6-46CF-AE8C-13686517AC5F},1\""
    "id": "1-e13f257d-78c6-46cf-ae8c-13686517ac5f",
    

  • 我自己使用过这个,但我会小心并确保您的代码不仅仅使用 eTag(我查看了 eTagownername 属性).它不受支持",因此这可能会发生变化,因此比较多个属性可以防止发生意外.

    I've used this myself but I would be careful and make sure your code used more than just the eTag (I looked at the eTag, the owner, and the name properties). It isn't "supported" so it's possible this could change so comparing multiple properties could prevent a mishap down the just.

    哦,不要告诉任何人.这只是我们之间.;)

    Oh, and don't tell anyone. This is just between us. ;)

    这篇关于如何使用 MS Graph 从 driveItem 中查找 OneNote Notebook 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆