---
title: "빈방 임시 대기중 - Threads API 토큰 갱신 및 Flake 전환"
url: "https://notes.junghanacs.com/notes/20260121T133045"
author: "Junghan Kim"
date: "2026-01-21T13:30:00+09:00"
lastmod: "2026-01-21T00:00:00+09:00"
tags: ["bib","nix","temp","thread","token"]
description: "Threads API 토큰 갱신과 Nix Flake 전환 과정을 기록한 운영 노트이다."
---

> [!abstract] 이 노트에 대하여
> 
> 만료된 Threads API 토큰을 새 방식으로 갱신하고 관련 프로젝트를 Flake 구조로 옮기는 과정을 정리한다. 배포 자동화와 소셜 연동 인프라의 유지보수 노트다.

## 히스토리

-   [2026-08-12 Wed 15:22] 중요한데 이거 memex-kb에 다 반영된 로직이야. 이거 글로 정리할 만한 가치는 없나? 아 threads의 토큰 갱신이 아주 번거로운 구조였지. 아마 그럴거야. 이 관점에서 필요하면 memex-kb 리포에만 넣자. 글은 이런 것은 필요 없다.
-   [2026-01-21 Wed 22:18] 이거 매우 중요해.

## 관련메타

-   [† #내보내기 #업데이트 #개정 #갱신](https://notes.junghanacs.com/meta/20250416T171517)
-   [† #스레드 #트위터](https://notes.junghanacs.com/meta/20240922T095350)
-   [@힣: #모음 #어쏠리즘 #아포리즘 (@junghanacs)](https://notes.junghanacs.com/notes/20250311T131725)

## 관련노트

-   [1j2c † #메멕스 #셀프트레킹](https://notes.junghanacs.com/meta/20250429T103134)
-   [§memex-kb: Legacy 문서 RAG 파이프라인 입구](https://notes.junghanacs.com/notes/20251030T011105)
-   [#셀프트레킹 #메맥스 Quantified-self](https://notes.junghanacs.com/notes/20230905T154400)
-   [¤gitleaks ¤secretlint 시크릿린트 - 리포 보안 정보 삭제 정리](https://notes.junghanacs.com/notes/20250131T190035)

## Threads API 토큰 갱신 및 memex-kb Flake 전환

[2026-01-21 Wed 22:27]

### 배경

memex-kb 프로젝트의 Threads API 토큰이 만료되어 갱신 작업 진행. 기존 방법(User Token Generator)이 작동하지 않아 새로운 방법 발견.

### 핵심 발견: Graph API Explorer + threads.net API

#### 토큰 발급 방법 (2026-01-21 검증)

1.  Graph API Explorer 접속
    -   <https://developers.facebook.com/tools/explorer/1351795096326806/>

2.  **중요**: 상단 드롭다운에서 API를 `threads.net` 으로 변경
    -   기본값은 `graph.facebook.com` 이라 작동 안 함

3.  "Generate Access Token" 클릭 → 단기 토큰 획득

4.  장기 토큰(60일)으로 교환:
    ```bash
    nix develop --command python scripts/refresh_threads_token.py --exchange "단기토큰"
    ```

#### 왜 User Token Generator는 안 됐나

-   테스터 계정 매칭 문제
-   "Invalid Auth Code: Credentials entered do not match the selected tester profile"
-   Meta의 복잡한 계정 체계 (Facebook/Instagram/Threads)

### memex-kb 개선 작업

#### 1. Nix Flake 전환

`shell.nix` → `flake.nix` 전환으로 빌드 속도 개선.

```bash
# 이전 (느림 - 매번 nixpkgs 평가)
nix-shell --run "python scripts/..."

# 이후 (빠름 - 캐싱)
nix develop --command python scripts/...
```

#### 2. 토큰 갱신 스크립트 생성

`scripts/refresh_threads_token.py` 생성:

```bash
# 단기 → 장기 토큰 교환 (가장 많이 사용)
python refresh_threads_token.py --exchange "THAA..."

# 현재 토큰 테스트
python refresh_threads_token.py --test

# 기존 장기 토큰 갱신 (만료 전)
python refresh_threads_token.py
```

#### 3. secretlint → gitleaks 교체

npm 의존성 제거, Nix로 통합.

```bash
# git repo 스캔
gitleaks detect

# 일반 파일 스캔 (디지털 가든 배포 전 검사용)
gitleaks detect --source=/path/to/files --no-git
```

#### 4. direnv 연동

`.envrc` 추가로 디렉토리 진입 시 자동 환경 로드.

### 삭제된 파일

-   `shell.nix` → `flake.nix` 로 대체
-   `requirements.txt` → `flake.nix` 에서 Python 패키지 관리
-   `package.json`, `package-lock.json` → `gitleaks` 로 대체

### 스레드 내보내기 파이프라인

#### 내보내기 명령

```bash
nix develop --command python scripts/threads_exporter.py --download-images
```

#### 출력 위치

-   memex-kb: `docs/threads-aphorisms.org`
-   디지털 가든 배포용: [힣 모음 - 어쏠리즘/아포리즘](https://notes.junghanacs.com/notes/20250311T131725)

### 60일 후 갱신 체크리스트

```markdown
[ ] 1. Graph API Explorer 접속
      https://developers.facebook.com/tools/explorer/1351795096326806/
[ ] 2. API를 "threads.net"으로 변경
[ ] 3. Generate Access Token → 단기 토큰 복사
[ ] 4. 장기 토큰 교환:
      nix develop --command python scripts/refresh_threads_token.py --exchange "토큰"
[ ] 5. 테스트:
      nix develop --command python scripts/refresh_threads_token.py --test
```

### 커밋

-   커밋: `7007e92`
-   메시지: "refactor: Migrate to Nix flake and add Threads token refresh script"

### 관련 문서

-   [Threads Aphorism Exporter 프로젝트](https://github.com/junghan0611/memex-kb/blob/main/docs/20251107T123200--threads-aphorism-exporter-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8__threads_aphorism_assholism.org)
-   [refresh_threads_token.py](https://github.com/junghan0611/memex-kb/blob/main/scripts/refresh_threads_token.py)
-   [flake.nix](https://github.com/junghan0611/memex-kb/blob/main/flake.nix)
