pip install notion-client
,可參考官方文件的說明其中也有使用教學notion.blocks.children.append(block_id = 新頁面id ,children)
在該頁面中append元件範例中pages.create()的方法及 your_notion_secret & your_database_id 在上一篇文章中有說明,其餘的code把子元件的type設定為嵌入連結 -> url設定為google首頁 -> 把子元件append到新頁面:
from notion_client import Client
# Initialize Notion client with your integration token
notion = Client(auth="your_notion_secret")
# Create a new page
new_page = notion.pages.create(
parent={"database_id": "your_database_id"},
properties={
"title": {
"title": [
{
"text": {
"content": "Your Page Title"
}
}
]
}
}
)
page_id = new_page['id'] #儲存新頁面的id
# Append a child block to the new page
notion.blocks.children.append(
block_id=page_id,
children=[ #要append在新頁面中的元件
{
"object": "block",
"type": "embed",
"embed": {
"url": "https://www.google.com"
}
}
]
)
print(f"Page created with ID: {page_id}")