vaayne / NotionAI-Plus

NotionAI Plus is a browser extension that adds NotionAI's powerful features to any website you visit
https://chrome.google.com/webstore/detail/notionai-plus/ilgkcoockdhdpkikaakkjacblhpmdmeo
MIT License
283 stars 27 forks source link

token not work #28

Closed kennychan07811 closed 1 year ago

kennychan07811 commented 1 year ago
r = requests.post(url, headers=cls._build_headers(token))

TypeError: _build_headers() missing 1 required positional argument: 'token'

vaayne commented 1 year ago

I see, there's a bug. I'll fix it. Thanks for raising

vaayne commented 1 year ago

@kennychan07811 please update to latest version and retry, I have a fix for that https://github.com/Vaayne/NotionAI/commit/734b331b38c3a4dc191bf601ffeb3163dc395113

kennychan07811 commented 1 year ago

i have the error

def get_spaces(cls, token: str) -> list[dict]: TypeError: 'type' object is not subscriptable

vaayne commented 1 year ago

@kennychan07811 could you try this python script, and check the full result

import os

import requests

TOKEN = os.getenv("NOTION_TOKEN")

def main():
    url = "https://www.notion.so/api/v3/getSpaces"
    headers = {
            "accept": "application/json",
            "Cookie": "; ".join(["token_v2=" + TOKEN]),
            "Content-Type": "application/json",
        }
    r = requests.post(url, headers=headers)
    if r.status_code != 200:
        raise ValueError("Cannot get spaces")
    res = r.json()
    print(res)
    spaces = []
    for _, val in res.items():
        space = val.get("space")
        if space:
            for k, v in space.items():
                space_id = k
                space_name = v["value"]["name"]
                spaces.append({"id": space_id, "name": space_name})
    return spaces

if __name__ == "__main__":
    res = print(main())
kennychan07811 commented 1 year ago
"Cookie": "; ".join(["token_v2=" + TOKEN]),

TypeError: can only concatenate str (not "NoneType") to str

vaayne commented 1 year ago

It seems that you have not set the TOKEN environment variable correctly. You can replace this with a hard-coded string instead.