{
  "name": "[Template] Refresh Threads Token",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -480,
        608
      ],
      "id": "7f18ba52-44c7-456b-970a-c43aec40949d",
      "name": "觸發以換取長期Token"
    },
    {
      "parameters": {
        "content": "# 1st. Get Your First Long Term Token\n將紅色區塊的節點資料\n換成你個人的參數後\n點擊觸發該流程",
        "height": 356,
        "width": 980,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -544,
        432
      ],
      "id": "5d07d7ec-bea8-47fc-8bcc-c6c71f4553bf",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "url": "=https://graph.threads.net/access_token",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "th_exchange_token"
            },
            {
              "name": "client_secret",
              "value": "={{ $json.app_secret }}"
            },
            {
              "name": "access_token",
              "value": "={{ $json.short_term_token }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        0,
        608
      ],
      "id": "8cd4d856-75b0-47ec-89df-1c05b4e19e19",
      "name": "Token Extension1"
    },
    {
      "parameters": {
        "url": "https://graph.threads.net/refresh_access_token",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "th_refresh_token"
            },
            {
              "name": "access_token",
              "value": "={{ $json.property_long_live_token }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        16,
        1056
      ],
      "id": "59e6c8ff-0bcb-4c86-bdba-0d67a099ae15",
      "name": "Refresh Token1"
    },
    {
      "parameters": {
        "content": "# 2nd. Refresh Token Once A Month",
        "height": 428,
        "width": 980,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -544,
        800
      ],
      "id": "d423713c-7255-4240-b653-6005c3ffb82f",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "months"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -480,
        1056
      ],
      "id": "0813aab7-366a-4b8d-a413-b932027c67c9",
      "name": "Schedule Trigger1"
    },
    {
      "parameters": {
        "content": "## 請把所有紅底的節點換成你個人的設定\n### 個人設定包括 Credential, Token, Notion Database and Page 等...",
        "height": 80,
        "width": 976,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -544,
        336
      ],
      "id": "2b151c57-0fd6-47f6-a3fd-be79f6ae7971",
      "name": "Sticky Note10"
    },
    {
      "parameters": {
        "content": "請參考本模板的使用說明書或周身刀的文章，將該節點內的各項參數換成自己申請到的Threads API應用程式資料",
        "height": 272,
        "width": 230,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -288,
        496
      ],
      "id": "c6de63ce-bfa8-48c1-b574-e1503710a7a2",
      "name": "Sticky Note22"
    },
    {
      "parameters": {
        "content": "請修改欄位：\n- **Credential connect with**:\n改成你剛剛設置的Credential \"Meta Token\"\n- **Databace Page**:\n改成你存放Threads API的那筆Notion Databace Page ID",
        "height": 320,
        "width": 230,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -288,
        896
      ],
      "id": "e9a83bc9-fb21-493d-831f-b2a20a885481",
      "name": "Sticky Note23"
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": {
          "__rl": true,
          "value": "你的Notion Databace PageID",
          "mode": "id"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Long_Live_Token|rich_text",
              "textContent": "={{ $json.access_token }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        240,
        1056
      ],
      "id": "64b28933-041c-4180-99a0-bb2d444c45d9",
      "name": "Update a database page1",
      "credentials": {
        "notionApi": {
          "id": "ea74jhkSo1aYymDV",
          "name": "Meta Token"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "get",
        "pageId": {
          "__rl": true,
          "value": "你的Notion Databace PageID",
          "mode": "id"
        }
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        -240,
        1056
      ],
      "id": "96ba4dc6-49a5-43db-85e8-0e28fe295cc6",
      "name": "Get a database page1",
      "credentials": {
        "notionApi": {
          "id": "ea74jhkSo1aYymDV",
          "name": "Meta Token"
        }
      }
    },
    {
      "parameters": {
        "content": "### 參考來源\n此流程參考自周身刀。原本模板是將Token儲存在n8n的Datatable，小胡我根據自己的需求，改存放到Notion Database\n- [周身刀 文章與n8n模版](https://charlsondou.com/blog/threads-api-setup-n8n-auto-update)\n- [周身刀 YT影片教學](https://youtu.be/sXWLjMg4Am0?si=2NGSF-bsWeRTcqWP)",
        "width": 448
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -544,
        160
      ],
      "typeVersion": 1,
      "id": "d1de2fdd-0ac5-4f75-8750-eebeabb4a108",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "658597ec-3cf6-4e64-9f5f-463d8c66e908",
              "name": "short_term_token",
              "value": "你的short_term_token",
              "type": "string"
            },
            {
              "id": "8c6f4532-6a9c-4477-816e-51ff92cfe91e",
              "name": "app_id",
              "value": "你的app_id",
              "type": "string"
            },
            {
              "id": "d2d81e2b-52b1-48bc-bae9-cea2c982a9eb",
              "name": "app_secret",
              "value": "你的app_secret",
              "type": "string"
            },
            {
              "id": "19242c23-ca44-4de2-a9fc-695ea133c745",
              "name": "user_id",
              "value": "你的user_id",
              "type": "string"
            },
            {
              "id": "f6401cdd-c310-45a2-b98b-0dd1978802f4",
              "name": "Plataform",
              "value": "Threads",
              "type": "string"
            },
            {
              "id": "077a0fea-3d6a-4061-907c-132e7623c0cc",
              "name": "user_name",
              "value": "你的user_name",
              "type": "string"
            },
            {
              "id": "79a5f3ef-05db-434a-9d4f-e06ce5b31c24",
              "name": "Number",
              "value": 1,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -240,
        608
      ],
      "id": "984dfb2f-b520-4609-b570-52ff62250237",
      "name": "設置ID1",
      "notesInFlow": false
    },
    {
      "parameters": {
        "content": "請修改欄位：\n- **Credential connect with**:\n改成你剛剛設置的Credential \"Meta Token\"\n- **Database**:\n改為你的Notion database \"Meta Token Update\"",
        "height": 320,
        "width": 230,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        160,
        448
      ],
      "id": "75c92f5a-c3e6-447f-b5dc-4f83be9332b4",
      "name": "Sticky Note24"
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "",
          "mode": "list",
          "cachedResultName": "",
          "cachedResultUrl": ""
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "App_ID|rich_text",
              "textContent": "={{ $json.User_ID }}"
            },
            {
              "key": "Client_Secret|rich_text",
              "textContent": "={{ $json.Client_Secret }}"
            },
            {
              "key": "Long_Live_Token|rich_text",
              "textContent": "={{ $json.Long_Live_Token }}"
            },
            {
              "key": "Number|number",
              "numberValue": "={{ $json.Number }}"
            },
            {
              "key": "Platform|rich_text",
              "textContent": "={{ $json.Platform }}"
            },
            {
              "key": "User_ID|rich_text",
              "textContent": "={{ $json.User_ID }}"
            },
            {
              "key": "User_Name|title",
              "title": "={{ $json.User_Name }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        224,
        608
      ],
      "id": "f4e019e5-bc7f-4ab8-83c8-cfef6cfcc267",
      "name": "建立Threads API資料1",
      "credentials": {
        "notionApi": {
          "id": "ea74jhkSo1aYymDV",
          "name": "Meta Token"
        }
      }
    },
    {
      "parameters": {
        "content": "請修改欄位：\n- **Credential connect with**:\n改成你剛剛設置的Credential \"Meta Token\"\n- **Databace Page**:\n改成你存放Threads API的那筆Notion Databace Page ID",
        "height": 320,
        "width": 246,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        160,
        896
      ],
      "id": "34f38cdf-aad0-452e-a987-c10548b89e04",
      "name": "Sticky Note25"
    },
    {
      "parameters": {
        "content": "### 關於小胡 \n- [Portaly](https://portaly.cc/xiaohu)\n- [Threads](https://www.threads.com/@xiaohu2024)\n- [請小胡喝杯咖啡](https://portaly.cc/xiaohu/support)\n- [本篇模板的文字說明](https://xiaohuproposal.notion.site/n8n-Threads-Access-Token-2cfa09939185805f8e96eb2fb77852cd?pvs=74)",
        "width": 512,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        160
      ],
      "typeVersion": 1,
      "id": "751b0b6f-1502-429a-be51-46159c8688d4",
      "name": "Sticky Note"
    }
  ],
  "pinData": {},
  "connections": {
    "觸發以換取長期Token": {
      "main": [
        [
          {
            "node": "設置ID1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Token Extension1": {
      "main": [
        [
          {
            "node": "建立Threads API資料1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Refresh Token1": {
      "main": [
        [
          {
            "node": "Update a database page1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "Get a database page1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a database page1": {
      "main": [
        [
          {
            "node": "Refresh Token1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "設置ID1": {
      "main": [
        [
          {
            "node": "Token Extension1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "da949dc3-8491-4e04-874c-c53b830281a8",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "2834f87f6fbda323e17e06a85bbaa2b0976dffd138b6ee0a2c2125e5d43de0d1"
  },
  "id": "QKurHroegy4UQyaY",
  "tags": []
}