Third crossposting target on the ADR-065 loop (ADR-069). Text posts get a link preview, 1 image posts as IMAGE and 2-4 as a CAROUSEL (Meta fetches them from /media/), with alt text and the first tag as topic_tag. Posts are shortened to 500 characters, counting non-ASCII as UTF-8 bytes. Edits don't follow (the API has no edit); unpublish and delete remove the post. Retried creates check for an existing post first. The 60-day token is refreshed daily from the worker loop and kept in DATA_PATH/threads_token.json under a file lock; a new configured token replaces it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2.8 KiB
v2.6.0: Crossposting to Threads
Implements ADR-069.
What changed
starpunk/syndication.py:ThreadsClient(targetthreads); media entries now carry their publicurl;process_due()calls each client's optionalmaintain()hook, which Threads uses to refresh its token.starpunk/config.py:THREADS_ACCESS_TOKEN,THREADS_USERNAME,THREADS_NAME,THREADS_MAX_CHARS(500),THREADS_MAX_MEDIA(4).tests/test_syndication_threads.py: a fake Graph API covering text, image and carousel posts; container polling; edits not following; deletes (including posts already deleted by hand); a lost publish reply; permanent and rate-limit errors; and token refresh, persistence and replacement.
Configuration
| Variable | Meaning |
|---|---|
THREADS_ACCESS_TOKEN |
Long-lived Threads user token. Enables the target. |
THREADS_USERNAME |
Optional. Used for the Micropub syndicate-to uid (https://www.threads.com/@name) and for fallback links. |
THREADS_NAME |
Label in the editor (default Threads) |
After the first daily refresh, the working token lives in
DATA_PATH/threads_token.json. The configured value only seeds it.
Changing THREADS_ACCESS_TOKEN switches to the new token.
Getting a token (one time)
-
At https://developers.facebook.com/apps, create an app with the Access the Threads API use case.
-
Under the use case's permissions, add
threads_basic,threads_content_publishandthreads_delete. -
Under App roles → Roles, add your Threads account as a Threads tester. Accept the invite in Threads (Settings → Account → Website permissions → Invites). The app can stay in development mode.
-
In the use case settings, add
https://<site>/as a redirect URI. Then open:https://threads.net/oauth/authorize?client_id=APP_ID&redirect_uri=https://<site>/&scope=threads_basic,threads_content_publish,threads_delete&response_type=codeAfter you approve, the browser lands on
https://<site>/?code=.... Copy the code (drop a trailing#_). -
Exchange the code for a short-lived token, then exchange that for a long-lived one:
curl -s -X POST https://graph.threads.net/oauth/access_token \ -F client_id=APP_ID -F client_secret=APP_SECRET \ -F grant_type=authorization_code -F redirect_uri=https://<site>/ -F code=CODE curl -s "https://graph.threads.net/access_token?grant_type=th_exchange_token&client_secret=APP_SECRET&access_token=SHORT_TOKEN" -
Set
THREADS_ACCESS_TOKENto the long-livedaccess_token.
The app secret is only needed for these steps. StarPunk doesn't use it.
Not done
- Video, GIF and WebP images (Threads takes video by URL. StarPunk only stores still images, and Threads rejects GIF and WebP).
- Edits (no API for them).