Skip to content

feat: add TikTok publishing with Login Kit and the Content Posting API - #206

Open
kwstasna wants to merge 8 commits into
coollabsio:mainfrom
kwstasna:feat/tiktok
Open

kwstasna wants to merge 8 commits into
coollabsio:mainfrom
kwstasna:feat/tiktok

Conversation

@kwstasna

Copy link
Copy Markdown
Contributor

Summary

Adds TikTok as a connected account. It connects through Login Kit for web and publishes through the Content Posting API: one video, or a photo post of up to 35 images, either straight to the profile (Direct Post) or to the creator's TikTok inbox as a draft they finish in the app.

  • Composer: follows TikTok's Direct Post UX guidelines, which TikTok checks in app review.
  • Preview: draws TikTok's For You layout, like the Meta previews.
  • Publish-only, like Discord: TikTok has no metrics, engagement or messages here.
  • Two migrations: a nullable JSON tiktok_options column on post_targets for each target's TikTok settings, and two nullable columns on connected_accounts for the refresh-token reminder.

Builds on #205, which is the first three commits here. Review from "feat(accounts): connect TikTok accounts with Login Kit" onwards. I'll rebase once it merges.

Commits

The TikTok part is five commits, so it can be reviewed one at a time. tsc, Larastan and Pest pass at each of them.

  1. feat(accounts): connect TikTok accounts with Login Kit
    • A Socialite driver for TikTok's quirks: the client id is client_key, scopes are comma-separated, and token errors come back in the body.
    • Connecting needs all four scopes (user.info.basic, user.info.profile, video.publish, video.upload). A partial grant revokes the token TikTok just issued and says why. So does a connection refused because TikTok withheld the profile.
    • Access tokens are refreshed when they're used, under the per-account lock, and the rotated refresh token is stored. Like Bluesky, TikTok stays out of the scheduled refresh sweep.
    • Disconnecting revokes the grant at TikTok. The revoke is best effort and never blocks the delete.
    • The capability registries, analytics and the metrics cadence leave TikTok out.
    • Glyph, labels, account card, seeder, README and .env.example*.
    • Until the next commit the publish registry refuses TikTok, the way the metrics and engagement registries do, because the enum match must cover every platform.
  2. feat(publishing): publish videos and photo posts to TikTok
    • TikTokConnector sends media with PULL_FROM_URL from the public media URL.
    • Photos are converted to JPEG and scaled down to fit 1080×1920.
    • Status is polled until TikTok reports the post live, in the inbox, or failed.
    • Each target stores post mode, privacy, comment/duet/stitch and the commercial content disclosure in tiktok_options. A new target starts with nothing pre-selected, as TikTok requires.
    • One validator is shared by the composer requests, the public API and the MCP update_post tool. It allow-lists every value, and rejects promotion without a disclosure, private branded content, and TikTok settings on other platforms.
    • A creator info endpoint returns what the creator may do right now. At publish the connector reads it again and fails the post if a stored choice is no longer allowed, rather than changing it.
    • Sync pipelines send TikTok posts as inbox drafts, since no one is there to choose who can view them.
    • A duplicated post keeps its post mode. The settings TikTok wants chosen by hand start unset again.
    • Deleting only removes the post here; the web, API and MCP responses say it stays live on TikTok.
  3. feat(compose): TikTok post settings in the composer
    • A Post | Inbox draft switch in the toolbar, where Instagram and Facebook show Feed / Reels / Stories.
    • One "Posting as" card with:
      • who can view the post, taken from the creator's current options with no default;
      • comment, duet and stitch, grayed out when the creator turned them off in TikTok, with duet and stitch not offered on photo posts;
      • the commercial content disclosure.
    • The card says when TikTok's options can't be loaded and offers a retry.
    • The consent line links TikTok's Music Usage Confirmation, and the Branded Content Policy when it applies.
    • The client precheck matches the server's.
    • An inbox draft shows as "Sent to inbox" in the status chips and the published view.
    • The delete and sync pipeline dialogs say what TikTok does differently.
  4. feat(compose): preview TikTok posts in the For You layout
    • TikTok's own layout: the Following / For You header, the creator rail, bold hashtags and mentions, and "original sound".
    • Photo posts swipe one photo at a time.
    • The preview says when a post goes to the inbox instead of the profile.
    • Captions link TikTok hashtags and mentions to tiktok.com.
  5. feat(accounts): remind before a TikTok refresh token runs out
    • TikTok refresh tokens have a fixed lifetime counted from the grant (365 days in the sandbox), and a refresh doesn't extend it. Access tokens are only refreshed when something is published, so an idle account, or one past that lifetime, would lose its connection without warning.
    • TikTok returns how long each refresh token has left (refresh_expires_in) and asks clients to schedule from it. Two new nullable columns on connected_accounts:
      • refresh_token_expires_at is set on connect and on every refresh. TikTokUser carries it through Socialite, and TikTokTokenClient returns it.
      • reconnect_reminded_at makes sure the workspace is told only once.
    • The token sweep (accounts:refresh-tokens) refreshes a TikTok account at most once a day, while its refresh token is within 14 days of running out or its expiry is unknown. The short-lived access tokens are still left to the just-in-time refresh.
    • When a refresh doesn't move the date, AccountReconnectDueNotification goes to the workspace owner and to the member who connected the account. It goes out once, in-app and by email, under the same preference as "account needs attention".
    • The reminder resets when TikTok issues a new refresh token or the account is reconnected. A refused refresh still flags the account like any other failed refresh.

Setup

# TikTok — https://developers.tiktok.com (Login Kit + Content Posting API)
TIKTOK_CLIENT_KEY=
TIKTOK_CLIENT_SECRET=
TIKTOK_REDIRECT_URI="${APP_URL}/accounts/callback/tiktok"

In the TikTok developer portal:

  • Login Kit with that redirect URI (absolute HTTPS, exact match).
  • The Content Posting API with Direct Post turned on, and the four scopes above.
  • A verified URL property for the domain media is served from (the APP_URL host or the object storage domain). Both videos and photos use PULL_FROM_URL, so TikTok downloads every file from there. It must be public HTTPS with no redirect.
  • For a sandbox app, the TikTok account under Target users.

Until TikTok audits an app, Direct Post only works at Only me visibility, on private accounts, for at most five users a day. Inbox drafts don't have that limit, because the creator picks who can view the post in the TikTok app. The README covers all of this.

What isn't supported, and why

Feature Why
Deleting on TikTok The Content Posting API has no delete endpoint. Deleting removes the post in Shoutrrr only, and the UI, API and MCP say so.
Metrics TikTok's Display API needs another scope and another review. Left for a follow-up.
Comments / engagement, messages No API available to this kind of app.
Reposts, threads No API for reposting; a TikTok post is a single post.

Tested against TikTok

I ran this on a sandbox app with a test deployment on 2026-11-24 and 2026-11-25:

  • Connect: the consent screen listed all four scopes and the account was stored.
  • Creator info: a public account offered Everyone / Friends / Only me, and after switching it to private, Followers / Friends / Only me. Nothing was pre-selected, duet and stitch were hidden for photos, and publishing waited for a privacy choice.
  • Inbox drafts: a video and a two-photo post arrived in the TikTok inbox. TikTok pulled the files from the app's public URL.
  • Direct Post:
    • On a public account TikTok refused it with unaudited_client_can_only_post_to_private_accounts. The app showed a clear message and didn't retry on its own.
    • After the account went private, Retry published it, and a direct photo post published too.
  • Scheduled posts: an inbox draft scheduled after the access token had expired published on time, through the just-in-time refresh.
  • Delete, disconnect and reconnect:
    • The delete notice named the inbox draft.
    • Disconnecting revoked the grant: the old token then got access_token_invalid, and the TikTok app's list of authorized apps dropped it.
    • Reconnecting worked.
  • Token lifetimes: TikTok's docs say access tokens last two hours, but the sandbox issued 24-hour tokens. The code uses each response's expires_in, so it works either way.

Screenshots

These were taken on a local build with seeded demo accounts, and the creator info is sample data.

The connect menu is compared with upstream main run locally, using the same viewport and steps. Every other screen has no before, because TikTok isn't on main.

Accounts: connect menu

Before (main) After
Accounts page on main: Connect account menu lists X, Bluesky, LinkedIn, Facebook / Instagram, Threads, Discord; 6 connected Accounts page on this branch: the menu also lists TikTok; 7 connected

TikTok joins the Connect account menu, and the demo TikTok account brings the count from 6 to 7.

Composer: TikTok settings (after only)

Light Dark
Composer with a TikTok account: Posting as card with who can view, comment/duet/stitch, disclosure, and the Post / Inbox draft switch The same composer in dark mode

Composer: Inbox draft mode, and the For You preview (after only)

Inbox draft Preview
Inbox draft mode: the card explains that the caption, audience, interactions and disclosure are set in the TikTok app Composer beside the For You preview of the video with caption and hashtags
For You preview in dark mode

After publishing (after only)

Published view of an inbox draft Delete dialog
Published post view with 'Sent to the TikTok inbox' on the TikTok card Delete post dialog: the draft sent to the TikTok inbox is not removed; delete it in the TikTok app

Refresh-token reminder (after only)

Rendered with a demo TikTok account whose refresh token runs out in nine days.

In-app notification Email
Notifications panel: TikTok account needs reconnecting soon; TikTok stops renewing access for @test_tiktok on Dec 5, 2026 Email: TikTok stops renewing access for @test_tiktok on Dec 5, 2026. Reconnect it before then to keep publishing without interruption. Reconnect account button

Testing

  • 42 test files added or changed (+3.7k lines), all with faked HTTP. They cover:
    • connect, scopes and revoke;
    • token refresh and rotation;
    • publish (video, photos, inbox, polling, error mapping);
    • the shared validator through the web, API and MCP paths;
    • creator info, JPEG conversion and framing;
    • the duplicator, sync and delete responses;
    • the composer card, precheck and preview;
    • the refresh-token expiry on connect and refresh, the 14-day window, the once-a-day limit, and the single reminder and its reset.
  • Full gate at the tip: oxlint, oxfmt, tsc, vitest (1,039), Pint, Larastan and Pest (2,302).

Open questions

  • Column name: tiktok_options is named after the platform. Add Google Business Profile Local Posts #163 proposes a generic provider_options and feat(x): tag people in photos #199 adds a feature-named column. I'm happy to rename it to whatever you prefer.
  • Reminder for other platforms: the refresh-token reminder only covers TikTok for now. LinkedIn refresh tokens also have a fixed 365-day life, so it could be extended to them.

A change made while a save was in flight could be marked saved without
ever reaching the server. Picking Reels right after typing a caption did
exactly that: the editor blur flushed the caption, the click landed
before the flush's request started, 'saveStarted' overwrote the click's
dirty flag, and the save's success marked everything saved. The composer
kept showing Reels while the post stayed a feed post.

A finished save now carries the snapshot it sent, and the composer stays
dirty when anything it persists changed since that snapshot. A debounced
save that fires while another is running now queues behind it instead of
being skipped, since nothing re-armed the debounce once the running save
landed.
…text

The counter turned red whenever the active account was blocked, so an
Instagram Reel without a video showed "85 / 2200" in red as if the
caption were too long. Stories without media did the same.

The counter now goes red only for an empty post, a section over the limit
or too many sections. Any other block still marks the account's tab, and
the reason is still listed where it was.
The first save of a new draft sent no per-account choices, and the store
request had no rules for them, so a format picked before the draft
existed was dropped. Picking Reels for an Instagram account and then
typing the caption was enough: the create made a feed post, marked the
composer saved, and no later save sent the format.

The first save now sends each account's format, and the store request
validates it with the same rule as an update.
Adds TikTok as a platform and connects it through TikTok Login Kit for
web.

- A Socialite driver for TikTok, which names the client id `client_key`,
  separates scopes with commas and reports token errors in the body.
- Connecting needs every scope (user.info.basic, user.info.profile,
  video.publish, video.upload). A partial grant, or a connection refused
  because TikTok withheld the profile, revokes the token TikTok just
  issued and says why, unless another connected account uses the same
  TikTok user.
- Access tokens last two hours and are refreshed when they are used,
  under the per-account lock, storing the rotated refresh token. Like
  Bluesky, TikTok stays out of the scheduled refresh sweep.
- Disconnecting revokes the grant at TikTok without going through
  TokenManager, so a dead refresh token doesn't flag an account that is
  being deleted. The revoke is best effort and never blocks the delete.
- TikTok has no metrics, engagement or messaging here, so the capability
  registries, analytics and the metrics cadence leave it out.
- The platform glyph, labels, account card and seeder know TikTok, and
  the README and env examples cover the app setup.

Publishing is added separately; until then the publish registry refuses
TikTok.
Publishes through the Content Posting API: one video, or a photo post of
up to 35 images, either to the profile (Direct Post) or to the creator's
TikTok inbox as a draft they finish in the app.

- Each TikTok target stores its own post settings in a `tiktok_options`
  column: post mode, privacy, comment/duet/stitch, and the commercial
  content disclosure. A new target starts with nothing pre-selected, as
  TikTok's guidelines require.
- The composer requests, the public API and the MCP `update_post` tool
  share one validator. It allow-lists every value and rejects promotion
  without disclosure, private branded content, and TikTok settings on
  other platforms.
- A creator info endpoint reads what the creator may do right now, and
  its calls are metered like the other TikTok calls. At publish the
  connector reads it again and fails the post if a stored choice is no
  longer allowed, instead of changing it.
- Media goes over PULL_FROM_URL from the public media URL. Photos are
  converted to JPEG and scaled down to fit 1080x1920. Status is polled
  until TikTok reports the post live, in the inbox, or failed, and a post
  uploaded again gets its full poll budget.
- The precheck holds a Direct Post until privacy and the disclosure
  choices are complete, and flags media TikTok can't take.
- A public post stores its TikTok post id for linking to it. An inbox
  draft is reported as sent to the inbox rather than published.
- Sync pipelines send TikTok inbox drafts, since nobody is there to pick
  who can view the post. A duplicated post keeps its post mode; the
  settings TikTok wants set by hand start unset again.
- TikTok has no delete endpoint, so deleting a post only removes it
  here. The web, API and MCP responses say it stays live on TikTok and
  report a remote delete only when one was queued.
Follows TikTok's Direct Post UX guidelines when a TikTok account is a
destination.

- A "Post | Inbox draft" switch in the toolbar, where Instagram and
  Facebook pick Feed / Reels / Stories, chooses between Direct Post and
  a draft sent to the creator's TikTok inbox.
- One card headed by the TikTok mark and "Posting as" the creator holds
  who can view the post (from the creator's current options, with no
  default), comment/duet/stitch, and the commercial content disclosure.
  Interactions the creator turned off in TikTok are greyed out, a duet
  or stitch is not offered on a photo post, and the card says when
  TikTok's options can't be loaded and offers a retry.
- Publishing stays disabled, with the reason, while the disclosure is on
  but neither option is picked. The consent line links TikTok's Music
  Usage Confirmation, and the Branded Content Policy when it applies.
- The composer's precheck matches the server's: privacy, the disclosure
  and the creator's longest allowed video.
- Settings chosen before the draft exists are sent on the first save,
  and a change made while an autosave is running is saved too.
- An inbox draft shows as "Sent to inbox" in the status chips and on the
  published view, a public post links to TikTok, and the delete and sync
  pipeline dialogs say what TikTok does differently.
- The README lists TikTok and the limits of an unaudited app.
Like the other networks' previews, the TikTok preview draws TikTok's own
chrome: the Following / For You header, the creator rail (avatar with the
red follow badge, TikTok's like, comment, save and share icons, and the
spinning sound disc), the bold username, a caption with bold white
hashtags and mentions, and "original sound - username". The rail sits
beside the caption so they never overlap. Photo posts swipe one photo at
a time with TikTok's dots, and an empty draft gets a TikTok-tinted
background, like the Reels and Story frames. The preview also says when
a post goes to the inbox instead of the profile.

Captions link TikTok hashtags and mentions to tiktok.com and leave URLs
as text, since TikTok does not link them either.
TikTok refresh tokens have a fixed lifetime counted from the grant, and
a refresh doesn't extend it. Access tokens are only refreshed when
something is published, so an idle account, or one past that lifetime,
lost its connection without warning.

TikTok returns how long each refresh token has left (refresh_expires_in)
and asks clients to schedule from it. That expiry is now stored on
connect and on every refresh, in a new `refresh_token_expires_at`
column. The token sweep refreshes a TikTok account at most once a day
while its refresh token is within 14 days of running out, or while its
expiry is unknown; the short-lived access tokens are still left to the
just-in-time path. When the date doesn't move, the workspace is told
once to reconnect before then (`reconnect_reminded_at`). A new refresh
token or a reconnect clears the reminder, and a refused refresh flags
the account like any other failed refresh.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant