PHPackages                             justinholtweb/craft-tokr - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. justinholtweb/craft-tokr

ActiveCraft-plugin[Authentication &amp; Authorization](/categories/authentication)

justinholtweb/craft-tokr
========================

TikTok feeds for Craft CMS — connect an account once, keep its videos in your own database, and drop a configurable, cached feed into any template.

5.0.0(yesterday)11↑2900%proprietaryPHPPHP ^8.2

Since Aug 23Pushed today1 watchersCompare

[ Source](https://github.com/justinholtweb/craft-tokr)[ Packagist](https://packagist.org/packages/justinholtweb/craft-tokr)[ RSS](/packages/justinholtweb-craft-tokr/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Tokr
====

[](#tokr)

TikTok feeds for Craft CMS 5.

Connect a TikTok account once, and Tokr keeps a local copy of its profile and videos in your database. Front-end requests read from that copy, so your pages never wait on TikTok's API — and never break when it's slow.

Requirements
------------

[](#requirements)

- Craft CMS 5.3 or later
- PHP 8.2 or later
- A [TikTok for Developers](https://developers.tiktok.com/) app with **Login Kit**and **Display API** added

Installation
------------

[](#installation)

```
composer require justinholtweb/craft-tokr
php craft plugin/install tokr
```

Or find **Tokr** in the Craft Plugin Store.

Tokr is a single paid edition, $99 one-off. There is no free tier and nothing is gated — the plugin you install is the whole plugin.

Setting up the TikTok app
-------------------------

[](#setting-up-the-tiktok-app)

1. Create an app at [developers.tiktok.com](https://developers.tiktok.com/).
2. Add the **Login Kit** and **Display API** products.
3. Under Login Kit, add a redirect URI. Tokr shows the exact value it expects at **Settings → Plugins → Tokr**; it looks like `https://example.com/tokr/oauth/callback`. TikTok requires HTTPS and an exact match.
4. Request the scopes you need: `user.info.basic` and `video.list` are required, `user.info.profile` gets you the bio and username, and `user.info.stats` gets you follower and like counts.
5. Copy the client key and secret into Tokr's settings. Both fields accept environment variables — `$TIKTOK_CLIENT_SECRET` — which is the right way to handle the secret.

While your app is in TikTok's sandbox, only accounts you've added as target users can be connected.

Connecting an account
---------------------

[](#connecting-an-account)

**Tokr → Accounts → Connect an account** sends you through TikTok's authorization screen and back. Tokr stores the access and refresh tokens encrypted with your `securityKey` and renews the access token on its own.

TikTok refresh tokens last a year. When one expires the account is flagged **Needs reconnecting** on the Accounts screen and you'll need to run through authorization again.

Feeds
-----

[](#feeds)

A feed is a saved set of display options. Create one under **Tokr → Feeds**, give it a handle, and render it:

```
{{ craft.tokr.render('homepage') }}
```

That's the whole integration. Everything else — layout, column counts, captions, click behavior — is configured in the control panel.

### Building your own markup

[](#building-your-own-markup)

If you'd rather write the HTML yourself:

```
{% set feed = craft.tokr.feed('homepage') %}
{% set account = feed.account %}

{{ account.displayName }} — {{ account.followerCount|number }} followers

    {% for video in feed.videos %}

            {{ video.captionHtml }}
            {{ video.likeCount|number }} likes · {{ video.durationFormatted }}

    {% endfor %}

```

### Overriding the bundled template

[](#overriding-the-bundled-template)

Create `_tokr/feed.twig` in your own templates folder and Tokr will render it instead of its own, passing `feed`, `account`, and `videos`. Copy `vendor/justinholtweb/craft-tokr/src/templates/_frontend/feed.twig` as a starting point.

Twig reference
--------------

[](#twig-reference)

CallReturns`craft.tokr.render('handle')`The rendered feed markup`craft.tokr.render('handle', { … })`Same, with extra template variables`craft.tokr.feed('handle')`A `Feed` model`craft.tokr.feeds()`Every feed`craft.tokr.videos('handle')`A feed's `Video` models`craft.tokr.account('@username')`An `Account` model, by username or ID`craft.tokr.accounts()`Every connected account**Video properties:** `videoId`, `caption`, `captionHtml`, `title`, `description`, `coverImageUrl`, `url`, `embedUrl`, `duration`, `durationFormatted`, `aspectRatio`, `width`, `height`, `likeCount`, `commentCount`, `shareCount`, `viewCount`, `postedAt`, `account`.

**Account properties:** `name`, `username`, `handle`, `displayName`, `avatarUrl`, `bioDescription`, `profileUrl`, `isVerified`, `followerCount`, `followingCount`, `likesCount`, `videoCount`, `isConnected`, `dateRefreshed`.

Keeping feeds fresh
-------------------

[](#keeping-feeds-fresh)

By default, the first front-end request after a feed goes stale queues a background refresh job, and the page renders from what's already stored.

The more predictable option is cron:

```
*/30 * * * * cd /path/to/project && php craft tokr/refresh
```

- `php craft tokr/refresh` — refresh every stale account
- `php craft tokr/refresh --force` — refresh everything regardless
- `php craft tokr/refresh/account @username` — refresh one account

If you go the cron route, turn off **Refresh in the background** in the settings so front-end requests never queue anything.

### About thumbnail expiry

[](#about-thumbnail-expiry)

TikTok's `cover_image_url` values are signed and stop working roughly six hours after they're issued. This is a TikTok constraint, not a Tokr one. Keep the refresh interval below six hours (Tokr caps it at five) so thumbnails are always replaced before they die.

Settings
--------

[](#settings)

Settings live at **Settings → Plugins → Tokr**, or in `config/tokr.php`:

```
