Integrate an Instagram Feed with Shopify Hydrogen
This guide is for Shopify Hydrogen storefronts. Building on Next.js? See the Next.js overview.
What you will build
Prerequisites
- A Meta app configured for Instagram API with Instagram Login.
- A connected Instagram professional account.
- The permissions required to read the account’s media.
- A long-lived Instagram user access token.
- A Hydrogen server runtime such as Shopify Oxygen.
Define a storefront media shape
Keep Instagram’s response details out of the UI by mapping them into a small stable type.thumbnail_url for the image tile because their media_url points to the video file. Carousel posts need their children field requested explicitly.
Fetch media on the server
Cache media briefly
Instagram media URLs are signed CDN URLs that expire. A cache lifetime that works for product or CMS data can serve broken Instagram images. Use a short public cache with stale-while-revalidate, for example:weaverse.fetchWithCache, pass the same bounded URL and cache strategy through the component loader. If you use the platform Cache API directly, exclude the token from human-readable logs and cache diagnostics.
Load data in a Weaverse section
A server component loader can read presentation settings, fetch Instagram, and return normalized data to the section.- Heading and link label.
- Number of posts.
- Grid columns and spacing.
- Media-type filters.
- Caption and lightbox behavior.
Render the feed
children for carousel slides and the video mediaUrl for playback. Keep the Instagram permalink available as an accessible fallback.
Refresh long-lived tokens
Long-lived Instagram tokens expire and can be refreshed through:- Refresh before the token’s expiry window.
- Run refresh work in the background when the runtime supports
waitUntil. - Persist the returned token and its expiry in server-controlled storage.
- Back off after failures instead of retrying on every page request.
- Fall back to the current token until it actually expires.
- Alert the team when refresh continues to fail.
Handle API version changes
Pin the Graph API version in one server module, not across components. Before Meta retires that version:- Read the Instagram Platform changelog.
- Update the version and requested fields.
- Run media and token-refresh tests.
- Verify images, videos, and carousels on a deployed storefront.
Configure CSP
Server-side Graph requests do not require browserconnect-src access. The browser still loads signed Instagram CDN media, so a strict CSP may need the current Instagram image/video hosts in img-src and media-src.
Inspect the returned media URLs and browser violations in the deployed environment. Avoid allowing all Meta domains when only specific CDN origins are required.
Test the integration
- Test image, video, and carousel posts.
- Test an account with fewer posts than the requested limit.
- Confirm an expired or invalid token produces safe fallback UI.
- Verify no token appears in HTML, browser requests, Studio data, or logs.
- Test cache expiry and stale-while-revalidate behavior.
- Test lightbox and external links on mobile and desktop.
- Run token-refresh tests with a mock upstream response.
- Navigate between pages repeatedly and confirm the same canonical feed state does not flicker or reorder unexpectedly.
Production checklist
- Instagram Login, not the retired Basic Display API, is configured.
- The token stays server-only.
- API version and fields are centralized.
- Request limits are bounded.
- Signed media URLs use a short cache.
- Videos and carousels map to renderable media.
- Token refresh persists safely and backs off on failure.
- Errors never expose API responses or credentials.