Add a live Instagram feed to Nuxt
Show your latest Instagram posts in Nuxt 3 or 4 with a Nitro server route and useFetch. We handle Instagram authorisation and token refresh; Nuxt renders the gallery, and the API key never reaches the browser.
Why doing it yourself breaks
- Instagram Basic Display was shut down on 4 December 2024, so many Nuxt tutorials and modules no longer work.
- The Instagram API with Instagram Login needs a Business or Creator account, a Meta app and a long-lived token that lasts 60 days and must be refreshed. See our access token guide for the details.
media_urllinks point at Instagram's CDN and expire, so a cached page ends up with broken images.
Feedframer is a data API: connect your Instagram account once, and we refresh the token server-side, copy images and videos to our CDN and give you one URL. Every plan has unlimited API calls, no view metering, and REST JSON, GraphQL and RSS. Free covers a typical single small-business site: one account and its six latest posts, updated daily. Premium adds up to five accounts, up to 100 posts per request and hourly updates; see pricing.
1. Connect the Instagram account
Create a free account , connect an Instagram Business or Creator account, wait for the import to finish and copy its API key from the dashboard. The account owner must authorise the connection: typing a public username does not connect an arbitrary account. Personal Instagram accounts cannot be connected.
2. Keep the key in server-only runtime config
Add this to your local .env and to your host's environment settings:
NUXT_FEEDFRAMER_API_KEY=YOUR_API_KEY Then declare it in nuxt.config.ts:
// nuxt.config.ts
export default defineNuxtConfig({
// Server-only: never under `public`. Nuxt fills it from NUXT_FEEDFRAMER_API_KEY.
runtimeConfig: { feedframerApiKey: '' },
// Cache the feed route for an hour, in line with Feedframer's own edge cache.
routeRules: { '/api/feed': { swr: 3600 } },
}); Keep .env out of Git. Do not put the key under runtimeConfig.public or call Feedframer from a client-side component: anything public is shipped to the browser.
3. Add a Nitro server route
Create server/api/feed.get.ts. It calls the documented REST endpoint and returns only what the grid needs: top-level posts, with mediaUrl for images, thumbnailUrl for videos (a video's mediaUrl is usually an MP4) and permalink for the link. Posts without a displayable image are omitted.
// server/api/feed.get.ts
type Post = {
id: string;
mediaType: 'IMAGE' | 'VIDEO' | 'CAROUSEL_ALBUM';
mediaUrl: string;
thumbnailUrl: string | null;
permalink: string;
altText?: string | null;
};
export default defineEventHandler(async () => {
const { feedframerApiKey } = useRuntimeConfig();
if (!feedframerApiKey) return { posts: [] };
try {
const feed = await $fetch<{ status?: string; posts?: Post[] }>(
'https://feedframer.com/api/v1/me',
{ query: { api_key: feedframerApiKey }, timeout: 10000 },
);
if (feed.status === 'invalid_token') {
console.warn('Feedframer: reconnect Instagram in the dashboard. Showing stored posts.');
}
const posts = Array.isArray(feed.posts) ? feed.posts : [];
return {
posts: posts.flatMap((post) => {
const src = post.mediaType === 'VIDEO' ? post.thumbnailUrl : post.mediaUrl;
return src
? [{ id: post.id, permalink: post.permalink, altText: post.altText ?? '', src }]
: [];
}),
};
} catch {
// Do not log request URLs: they contain the account API key.
console.warn('Feedframer: unable to load Instagram posts.');
return { posts: [] };
}
});4. Render the grid
Create components/InstaStrip.vue. useFetch runs during server rendering, so the posts are in the HTML on first load.
<!-- components/InstaStrip.vue -->
<script setup lang="ts">
const { data } = await useFetch('/api/feed', { default: () => ({ posts: [] }) });
</script>
<template>
<section aria-label="Latest Instagram posts">
<div v-if="data.posts.length > 0" class="instagram-grid">
<a v-for="post in data.posts" :key="post.id" :href="post.permalink"
target="_blank" rel="noopener noreferrer" aria-label="View this post on Instagram">
<img :src="post.src" :alt="post.altText"
width="400" height="400" loading="lazy" decoding="async" />
</a>
</div>
<p v-else>Our Instagram posts are temporarily unavailable.</p>
</section>
</template>
<style scoped>
.instagram-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; }
.instagram-grid img { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; }
@media (min-width: 48rem) { .instagram-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
</style> Use it from app.vue or any page:
<!-- app.vue or any page -->
<template>
<InstaStrip />
</template> If you already have styling, keep your grid classes and swap just the photo source for post.src. The sample shows a neutral unavailable message after a failed request; in production you may prefer your existing static images as a fallback.
5. Make sure new posts actually reach the page
Server-rendered Nuxt: the route fetches on request, and swr: 3600 caches it for up to an hour. Feedframer imports are daily on Free and hourly on Premium, and the API may be cached for up to an hour, so this is not a real-time Instagram webhook widget.
Static Nuxt (nuxt generate): the feed is fetched once at build time. Schedule a rebuild on your host, daily for Free or hourly for Premium if that freshness matters, and add the API key to the build environment.
Feedframer or Behold for a Nuxt Instagram widget?
If you want a live Instagram feed that matches a custom Nuxt layout, Feedframer supplies JSON while you control the HTML and CSS. We do not meter API calls or website views, we refresh tokens server-side, and you can use REST, GraphQL or RSS. Behold also supplies JSON and has a no-code widget builder, which we do not offer. If you would rather configure a ready-made gallery than maintain a component, Behold can be the better fit. See the current comparison .
Troubleshooting
- Empty gallery: check
NUXT_FEEDFRAMER_API_KEYis set on the host, the import has finished, and the account has posts. status: invalid_token: stored posts may still render, but the account owner must reconnect Instagram in the dashboard. Automatic token refresh cannot prevent every password change or revoked permission.- Videos missing: the grid needs a
thumbnailUrl. It deliberately skips videos without one. - Do not use
/api/v1/postsor a Bearer header. The endpoint is/api/v1/me?api_key=....