graphcentral / notion

Knowledge graph for Notion, like obsidian.md or Roam research / https://graphcentral.github.io/graph
https://graphcentral.github.io/graph
MIT License
64 stars 8 forks source link

Detailed Instructions for Setting up and Configuring Private NotionAPI #6

Closed jshingler closed 11 months ago

9oelM commented 11 months ago

Hey @jshingler thanks for posting this issue. It's actually supported right now. Just inject unofficialNotionAPI after initializing NotionAPI yourself. Instruction is at https://github.com/NotionX/react-notion-x#private-pages.

import { NotionGraph } from "@graphcentral/notion-graph-scraper"
import fs from "fs"
import { NotionAPI } from "notion-client";

/**
 * example of how to use `@graphcentral/notion-graph-scraper`
 */
;(async () => {
  const notionApi = new NotionAPI({
    activeUser: process.env.NOTION_ACTIVE_USER,
    authToken: process.env.NOTION_TOKEN_V2
  })
  const notionGraph = new NotionGraph({
    maxDiscoverableNodes: 2000,
    maxDiscoverableNodesInOtherSpaces: 2000,
    verbose: true,
    unofficialNotionAPI: notionApi,
  })
  const graph = await notionGraph.buildGraphFromRootNode(
    // Some random Japanese blog
    `95fcfe03257541c5aaa21dd43bdbc381`
  )
  console.log(graph.nodes.length)
  console.log(graph.links.length)
  await new Promise((resolve, reject) => {
    fs.writeFile(`test0.json`, JSON.stringify(graph), (err) => {
      if (err) reject(err)
      else resolve(``)
    })
  });

  process.exit(0)
})()