Skip to main content

Integrate an Instagram Feed with Shopify Hydrogen

The Instagram API with Instagram Login lets a Hydrogen storefront display recent images, videos, and carousel posts from a connected professional Instagram account. The access token must stay on the server; browser components should receive only normalized media data. This guide is based on a maintained Weaverse Hydrogen implementation that handles signed media URLs, carousel children, errors, and long-lived token refresh. Adapt the files and route boundaries to your project.

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.
Add the token to local and deployed server environment configuration:
INSTAGRAM_ACCESS_TOKEN is a server credential. Never prefix it with PUBLIC_, add it to a browser bundle, or expose it as a Weaverse Studio setting.

Define a storefront media shape

Keep Instagram’s response details out of the UI by mapping them into a small stable type.
Videos need 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

The access token appears in the upstream URL, so never log the URL or raw upstream error body.

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:
When using 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.
Expose only presentation choices in the schema:
  • Heading and link label.
  • Number of posts.
  • Grid columns and spacing.
  • Media-type filters.
  • Caption and lightbox behavior.
Do not expose the account token in Studio.

Render the feed

If the section opens media in a lightbox, use 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:
A durable rotation flow should:
  1. Refresh before the token’s expiry window.
  2. Run refresh work in the background when the runtime supports waitUntil.
  3. Persist the returned token and its expiry in server-controlled storage.
  4. Back off after failures instead of retrying on every page request.
  5. Fall back to the current token until it actually expires.
  6. Alert the team when refresh continues to fail.
Oxygen environment variables cannot be changed at runtime. Store the rotating token in a secure database, secret store, or restricted Shopify shop metafield written through the Admin API. Never return that metafield to the browser or Storefront API.

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.
Do not reuse examples written for the retired Instagram Basic Display API.

Configure CSP

Server-side Graph requests do not require browser connect-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

  1. Test image, video, and carousel posts.
  2. Test an account with fewer posts than the requested limit.
  3. Confirm an expired or invalid token produces safe fallback UI.
  4. Verify no token appears in HTML, browser requests, Studio data, or logs.
  5. Test cache expiry and stale-while-revalidate behavior.
  6. Test lightbox and external links on mobile and desktop.
  7. Run token-refresh tests with a mock upstream response.
  8. 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.

Official resources