代码之家  ›  专栏  ›  技术社区  ›  Dmitriy Popov takra

如何检索和创建切换标题块?

  •  0
  • Dmitriy Popov takra  · 技术社区  · 2 年前

    我想通过Notion API创建切换标题1-3。然而,我在API中找不到普通头和切换头之间的区别。

    https://developers.notion.com/reference/block#heading-one-blocks 此文档仅列出 "type": "heading_1" 而没有任何附加属性来区分切换标头与正常(非切换)标头。

    当我通过API获取toggle-header块时,我也看不到任何表明该头是toggle-cheader的属性: Getting a toggle heading 1 block via Notion API - IntelliJ Debugger

    是否可以通过API创建切换标题?如果是,那么怎么做?

    0 回复  |  直到 2 年前
        1
  •  0
  •   Dmitriy Popov takra    2 年前

    看起来API本身实际上支持使用 children 这将使标题成为切换标题。

    只是我使用的包装JVM库不支持将子级设置为HeadingOne、HeadingTwo和HeadingThree块。

    我为图书馆增加了一期,请参阅 https://github.com/seratch/notion-sdk-jvm/issues/45

    通过纯API的工作示例(替换 YOUR_PAGE_ID 使用您的Notion页面id),并设置 NOTION_API_TOKEN 到您的Notion代币:

    curl -X PATCH 'https://api.notion.com/v1/blocks/YOUR_PAGE_ID/children' \
      -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \
      -H "Content-Type: application/json" \
      -H "Notion-Version: 2022-02-22" \
      --data '{
      "children": [
        {
          "object": "block",
          "type": "heading_2",
          "heading_2": {
            "rich_text": [{ "type": "text", "text": { "content": "Heading 2 from script (try 3)" } }],
            "children": [
              {
                "object": "block",
                "type": "paragraph",
                "paragraph": {
                  "rich_text": [
                    {
                      "type": "text",
                      "text": {
                        "content": "Child in heading 2."
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }'
    
    推荐文章