notion.py 891 B

1234567891011121314151617181920212223242526272829
  1. from notion_client import Client
  2. # 首先设置环境变量 NOTION_API_SECRET,该值为你的 Notion API 密钥
  3. notion = Client(auth="secret_PvJWhkqlZJ7PMIqqPxWDhS736TjvUbkGojyrybjyxNh")
  4. # 填写你要创建文档的数据库 ID 和文档名称
  5. database_id = "0e213716cac641189939bf5c84662803"
  6. document_title = "YOUR_DOCUMENT_TITLE"
  7. try:
  8. # 在指定数据库中创建一个空白文档
  9. new_page = {
  10. "Name": {
  11. "title": [
  12. {
  13. "text": {
  14. "content": document_title
  15. }
  16. }]
  17. }
  18. }
  19. created_page = notion.pages.create(parent={"database_id": database_id}, properties=new_page)
  20. # 获取文档的公开 URL
  21. page_url = created_page['url']
  22. print("The URL of the created page is: ", page_url)
  23. except Exception as e:
  24. print("Encountered an error:", e)