我正在尝试获取 Notion 页面上内联子数据库的数据库 ID。
我尝试使用 GET 方法检索父页面。 (如下面的代码所示)
import requests, json
# Define my Notion API API_KEY
API_KEY = "secret_MyKey_:)"
# Define the Notion page URL
get_url = "https://api.notion.com/v1/pages/parent_page_id_:)"
# Set up headers for the API request
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Notion-Version": "2022-06-28",
}
# Making the API request
response = requests.get(page_url, headers=headers)
# Saving the results to a JSON file if the request is successful
if response.status_code == 200:
data = response.json()
with open("test.json", "w") as f:
json.dump(data, f)
else:
print(f"Failed to fetch child elements. Status code: {response.status_code}")
生成的 JSON 文件如下所示。
{
"object": "page",
"id": "page_id",
"created_time": "2023-09-14T02:02:00.000Z",
"last_edited_time": "2023-09-14T10:53:00.000Z",
"created_by": {
"object": "user",
"id": "my_id_:)"
},
"last_edited_by": {
"object": "user",
"id": "me :)"
},
"cover": null,
"icon": { "type": "emoji", "emoji": "\ud83d\udd2c" },
"archived": false,
"properties": {
"title": {
"id": "title",
"type": "title",
"title": [
{
"type": "text",
"text": { "content": "Testing Zone", "link": null },
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Testing Zone",
"href": null
}
]
}
},
"url": "https://www.notion.so/Testing-Zone-page_id",
"public_url": null
}
显然,子元素没有键。我想知道是否有另一种方法可以专门访问页面的子ID。如果你能帮助我,我会很高兴! 😇