The Instagram module puts the latest posts of your own Instagram account on a page, as a grid that opens each picture in a viewer or links through to Instagram. By the end of this chapter your site will have a feed block showing your account's posts, kept up to date by itself.
It is a module and not a feature (Modules): a site that does not list it has no tables and no scheduled job for it. It uses only Meta's official Instagram API. Nothing is scraped and no third-party feed service is involved.
It shows the posts of one Instagram professional account, which is a Business or Creator account: the account you connect. A personal account cannot be shown, because Meta's official API does not serve one. Switching is free and quick. In the Instagram app, open Settings, find “Account type and tools”, and choose “Switch to professional account”.
Other people's accounts by username, and hashtags, are not offered. Both need Facebook Login and a review by Meta, and hashtags also need business verification.
pnpm add @jamiemcconnell/cms-instagrammodules in site.config.ts:modules: ['@jamiemcconnell/cms-instagram'],pnpm cms migratepnpm dev with Ctrl+C and run it again. An Instagram entry now appears in the admin's sidebar, for admins.Instagram only lets a website read an account's posts through an app registered with Meta, the company behind Instagram and Facebook. Each site brings its own app. That keeps its keys and limits separate, and it needs no review from Meta. You do this once.
Meta renames its menus now and then, so if a label below differs a little, look for the nearest match.
developers.facebook.com with a Facebook account, and register as a Meta developer if it asks you to./api/admin/modules/instagram/callback, such as https://example.com/api/admin/modules/instagram/callback, and save. It must be https and match CMS_SITE_URL exactly. The Instagram screen in the admin shows the exact value to copy. Meta's dashboard may add a trailing slash when it saves; if it does, use the form it stored.Put the two values from step 5 in the site's .env. On a server that runs Docker, compose.yaml passes .env through to the site, so no other change is needed. Restart the site afterwards; on a server, docker compose up -d does it.
CMS_INSTAGRAM_APP_ID=your-instagram-app-id
CMS_INSTAGRAM_APP_SECRET=your-instagram-app-secretThe site copies the latest 24 posts into its own storage, because Instagram's image links expire. After that it syncs every hour and renews its access token by itself. To sync now, choose Sync now in the admin, or run this in your site's folder:
pnpm cms jobs run instagram:syncOn a server that runs Docker, run that as docker compose run --rm app pnpm cms jobs run instagram:sync. Disconnect, on the same screen, removes the stored token and every copied image.
Open a page in the editor and add the Instagram feed block, from the Elements group of the block picker. It has these settings:
Public pages are cached, so a new post can take up to five minutes after a sync to appear. Until an account is connected and has synced, editors see a placeholder note in the block and visitors see nothing.
CMS_SITE_URL, and mind a trailing slash that the dashboard may have added..env and restart the site.CMS_AUTH_SECRET, or an outage long enough for the token to expire, leaves a token that cannot be read or renewed. Choose Connect Instagram again.Run it on a server lists the environment variables, and Troubleshooting covers problems that are not about Instagram.