DunSocial CLI
使用 npm 套件 dunsocial 中的 dun 二進位檔。
npm install -g dunsocial
npx dunsocial …
建議在每個指令都加上 --json,讓輸出可以機器解析。
遠端主機(ChatGPT web、Claude web)請持續使用 DunSocial MCP。此 CLI 是為本地代理、終端機和 CI 設計的。
環境變數可以覆蓋 ~/.config/dunsocial/config.json。
設定
永遠遵循:認證 → 選擇工作區 → 驗證 → 列出帳戶 → 動作。
請勿自行杜撰社羣帳號 ID。請勿將 drafts create 視為成功發布。
互動式認證
在瀏覽器中前往 app.dunsocial.com/cli/authorize 核准:
dun auth login
無頭認證(CI)
在應用程式的設定 → CLI 中建立 PAT(dun_pat_…),然後:
export DUN_TOKEN="dun_pat_…"
export DUN_API_URL=https://api.dunsocial.com
DUN_API_URL 為選填(預設為正式環境)。
PAT 規則:
- 綁定到一個工作區;缺少作用域 → 退出碼
3/ 拒絕存取 - 無法管理其他權杖、計費或團隊
- 在 CI 中優先使用 PAT 而非瀏覽器工作階段權杖
工作區
互動式:
dun workspace list --json
dun workspace use <id-or-slug> --json
無頭(使用 PAT 時必須):
export DUN_WORKSPACE_ID="…"
驗證
dun auth status --json
dun workspace current --json
探索順序
dun auth status --jsondun workspace current --json(或list+use)dun accounts list --json— 擷取社羣帳號 id- 動作(排程 / 發布 / 草稿 / 媒體 / 記憶)
排程貼文
dun posts schedule \
--text "從 DunSocial CLI 出貨。" \
--accounts acc_x,acc_li \
--in 1h \
--json
絕對時間:--at 2026-06-01T09:00:00Z。
立即發布
dun posts publish --text "來自 dun 的問候" --accounts acc_x --json
媒體
先上傳,再附加回傳的資產 ID:
dun media upload ./shot.png --alt "產品截圖" --json
dun posts schedule --text "…" --accounts acc_x --media <assetId> --in 30m --json
草稿、記憶、討論串
dun drafts create --text "WIP" --platforms x,linkedin --json
dun memory collections list --json
dun memory save --collection <id> --text "…" --json
dun memory search --prompt "…" --collections <id> --json
討論串檔案格式:[{"content":"1"},{"content":"2"}]
dun posts schedule-thread --account acc_x --file ./thread.json --in 2h --json
破壞性操作
需要加上 --yes(或 CI=1)才能執行 delete。
退出碼
| 代碼 | 意義 |
|---|---|
| 0 | 成功 |
| 1 | 用法錯誤 |
| 2 | 認證錯誤 |
| 3 | 拒絕存取 / 缺少作用域 |
| 4 | 驗證錯誤 |
| 5 | 找不到 |
| 6 | 速率限制 |
| 7 | 網路錯誤 |
失敗時的 JSON:
{
"ok": false,
"error": {
"code": "validation",
"message": "…",
"details": null
}
}
常見陷阱
- 需要有工作區:
workspace use、--workspace或DUN_WORKSPACE_ID --accounts預期的是 DunSocial 社羣帳號的 id,而非使用者名稱- 在附加之前,先使用
media upload上傳本機檔案 - 平台特定選項:必要時使用
--meta '{"reddit":{"…"}}' - MCP OAuth 與 CLI 權杖是不同的系統
說明
dun --help
dun posts --help