← Blog

How to publish one video to YouTube, Instagram and Facebook through an API

Guide ·

There is no shared API. YouTube takes the file through a resumable upload, Instagram fetches it from a public URL into a container you poll and then publish, and a Facebook Page has one endpoint for Reels and another for Page videos. Doing it yourself means a Google project and a Meta app, each with its own sign-in, token refresh, review and ways to fail.

socialized.dev puts the three behind one request: upload the file once, name the platforms, and read each destination’s state, or receive a signed webhook, as it goes live. It’s free for 10 videos a month.

Platform How the file gets there What it becomes
YouTube You send the bytes, in a resumable upload A Short or a video: YouTube decides
Instagram Instagram fetches it from a public URL Always a Reel
Facebook Page Facebook fetches a URL, or you send the bytes A Reel or a Page video: you pick the endpoint

YouTube: a resumable upload

You need a Google Cloud project with the YouTube Data API enabled and an OAuth client asking for youtube.upload (plus youtube.readonly to read channel and processing status). Both are sensitive scopes, so until Google verifies your app only 100 people can grant them. Keep the OAuth app’s publishing status at “In production”: in “Testing”, refresh tokens expire after 7 days, which breaks any publish that runs while the user is away. Ask for access_type=offline and prompt=consent to get a refresh token at all.

The upload itself is two steps. First, send the video’s metadata and size; Google answers with a session URL in the Location header.

POST /upload/youtube/v3/videos?uploadType=resumable&part=snippet,status HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer ya29.…
Content-Type: application/json; charset=UTF-8
Content-Length: 163
X-Upload-Content-Type: video/mp4
X-Upload-Content-Length: 31457280

{
  "snippet": { "title": "Launch clip", "description": "Posted once, everywhere." },
  "status": { "privacyStatus": "public", "selfDeclaredMadeForKids": false }
}

Then PUT the bytes to that URL, in one request or in chunks with Content-Range. A chunk is a multiple of 256 KiB, and Google answers each one but the last with 308 and a Range header, which your code reads to know where to resume.

What catches people out:

  • There is no Shorts flag. A video that is vertical or square and 3:00 or less becomes a Short on its own, and the API never tells you whether it did.
  • Long videos need a verified channel. Over 15 minutes, a channel that hasn’t verified with a phone number gets its upload accepted, then rejected in processing with rejectionReason: length. You can read the channel’s status.longUploadsStatus from channels.list before you try.
  • Titles are strict. A title is at most 100 characters, and neither the title nor the description may contain < or >.
  • Quota runs out for the day. Uploads draw on your project’s daily quota, which resets at midnight Pacific time. Out of quota, YouTube answers 403 with quotaExceeded, and no retry gets through before the reset.

Instagram: a container you poll

Publishing goes through the Instagram API with Instagram Login (graph.instagram.com), for a professional account (Business or Creator), with the instagram_business_basic and instagram_business_content_publish permissions. On this path you never send Instagram the bytes: it fetches the video from a public URL, which has to stay reachable until processing finishes.

It takes three calls: create a container, wait for it, publish it.

# 1. Create the container. Instagram starts fetching the video.
curl -X POST "https://graph.instagram.com/$IG_USER_ID/media" \
  -H "Authorization: Bearer $IG_TOKEN" \
  -d media_type=REELS \
  -d video_url="https://media.example.com/clip.mp4" \
  --data-urlencode caption="Posted once, everywhere."
# → { "id": "<container id>" }

# 2. Ask until status_code is FINISHED (or ERROR, or EXPIRED).
curl "https://graph.instagram.com/$CONTAINER_ID?fields=status_code" \
  -H "Authorization: Bearer $IG_TOKEN"

# 3. Publish the finished container.
curl -X POST "https://graph.instagram.com/$IG_USER_ID/media_publish" \
  -H "Authorization: Bearer $IG_TOKEN" \
  -d creation_id="$CONTAINER_ID"

What catches people out:

  • Every video is a Reel. The API has no other kind of video post, so its limits are Instagram’s limits: 3 seconds to 15 minutes long and up to 300 MB. A longer or larger file can’t go to Instagram at all.
  • The caption is the only text. A Reel has no title, and its caption is at most 2,200 characters.
  • Tokens last 60 days. Refresh each one with ig_refresh_token on a schedule, before it lapses.

Facebook: two endpoints for one Page

A Page is published to with Facebook Login, the pages_show_list, pages_read_engagement and pages_manage_posts permissions, and a Page access token you get from the user’s token. Then you choose between two endpoints, and they work differently.

Reels (/{page-id}/video_reels) take three phases. Start a session, hand the file to the upload_url it returns (as a file_url header Facebook fetches, or as the bytes themselves), then finish it with video_state=PUBLISHED.

# 1. Start. Facebook answers with a video_id and an upload_url.
curl -X POST "https://graph.facebook.com/v25.0/$PAGE_ID/video_reels" \
  -H "Authorization: Bearer $PAGE_TOKEN" \
  -d upload_phase=start

# 2. Upload. Here Facebook fetches the file from your URL. The scheme is OAuth, not Bearer.
curl -X POST "$UPLOAD_URL" \
  -H "Authorization: OAuth $PAGE_TOKEN" \
  -H "file_url: https://media.example.com/clip.mp4"

# 3. Finish, and publish.
curl -X POST "https://graph.facebook.com/v25.0/$PAGE_ID/video_reels" \
  -H "Authorization: Bearer $PAGE_TOKEN" \
  -d upload_phase=finish \
  -d video_id="$VIDEO_ID" \
  -d video_state=PUBLISHED \
  --data-urlencode description="Posted once, everywhere."

Page videos (/{page-id}/videos) are one call with a file_url, or the bytes as source, or a resumable upload of their own. They take a title and a description, and much longer files.

What catches people out:

  • The documented Reel length is out of date. Meta’s Reels guide still says 90 seconds, but Meta has since raised Reels to about three minutes, and Reels over 90 seconds publish through the API. Page videos have no documented limit at all: ask the Page with GET /{page-id}?fields=video_upload_limits.
  • Your code has to choose. Reels are made for short vertical video, and a Page video is never a Reel, so pick the endpoint for each video from its shape and length.

Then everything after the upload

Getting the bytes in is the part the platforms document best. The rest is where the work is:

  • Three status models. YouTube reports processing through videos.list, Instagram through the container’s status_code, Facebook through the video’s status. Each needs its own polling, timeouts and meaning of “done”.
  • Grants that stop working. Tokens expire on different clocks, and a grant can stop working with no warning: a password change, a channel moved to another Google account, or Meta asking the account’s owner for a security check. Your code has to notice, stop publishing there, and ask the person to reconnect.
  • Retries that don’t post twice. A timeout on a publish call doesn’t tell you whether the post went live. A safe retry remembers what already did.
  • Two reviews. Google verifies the scopes you ask for. Meta’s App Review wants a written use and a screencast for each permission, showing the whole flow; until a permission is approved, only people with a role on your app can use it.

When to build it yourself

Building it is reasonable when you publish to one platform, or when you need what a video publishing API doesn’t do: Instagram Stories or carousels, image posts, comments, analytics. It is also the only option if you won’t let a third party hold the grants to your accounts: a publishing service has to hold them to publish for you (socialized.dev keeps them encrypted).

If what you need is one video, out to all three, from code, with an answer from each platform, that’s the job socialized.dev was built for.

The same job with socialized.dev

Connect each account once in the dashboard: connecting is the platform’s own sign-in, in a browser, and a brand holds one account per platform. After that you publish by platform name, and socialized.dev keeps each grant fresh.

From a terminal, the CLI uploads the file and publishes it in one command (in CI, set SOCIALIZED_DEV_API_KEY and SOCIALIZED_DEV_BRAND_ID instead of logging in; pass --brand-id if your account has more than one brand):

npm install -g @socialized.dev/cli
socialized.dev login
socialized.dev publications create \
  --brand-id "$BRAND_ID" \
  --video ./clip.mp4 \
  --title "Launch clip" \
  --description "Posted once, everywhere." \
  --targets '[
    { "platform": "youtube" },
    { "platform": "instagram" },
    { "platform": "facebook" }
  ]'

Over HTTP it is the same path in four steps. POST /assets plans the upload and returns one presigned URL for each 10 MiB part; you PUT each part and keep its ETag; POST /assets/{assetId}/complete records the file; and POST /brands/{brandId}/publications sends it to every destination, with an Idempotency-Key so a retry within 24 hours returns the same publication instead of posting twice (after that window, check the publication’s status before resubmitting):

{
  "videoAssetId": "asset_…",
  "title": "Launch clip",
  "description": "Posted once, everywhere.",
  "targets": [
    { "platform": "youtube", "options": { "privacyStatus": "unlisted" } },
    { "platform": "instagram" },
    { "platform": "facebook" }
  ]
}

The answer comes back at once, with what each platform will make of the video:

{
  "publicationId": "pub_…",
  "status": "queued",
  "targets": [
    {
      "id": "tgt_…",
      "platform": "youtube",
      "status": "pending",
      "format": "short",
      "formatChoice": "platform"
    },
    {
      "id": "tgt_…",
      "platform": "instagram",
      "status": "pending",
      "format": "reel",
      "formatChoice": "platform"
    },
    {
      "id": "tgt_…",
      "platform": "facebook",
      "status": "pending",
      "format": "reel",
      "formatChoice": "auto"
    }
  ]
}

What that request takes care of, from the sections above:

  • Limits are checked before anything is sent. A video a platform would refuse fails the request with 422 VideoNotAcceptedError, listing every limit it breaks on every destination; a title or caption too long for one platform fails with 422 PlatformMessageTooLongError, naming it.
  • Facebook’s endpoint is chosen for you. By default a video that is vertical or square and 3 seconds to 3 minutes long goes out as a Reel, and anything else as a Page video. Set format to reel or video in the Facebook options to choose yourself.
  • Each destination is its own job. It goes pending, processing, then published with the post’s externalUrl, or failed with a failure.kind that says what to do: reconnect, wait for the quota to reset, send a new file, or retry. A retry only ever resends a failed destination, so a post that went live is never posted twice.
  • You hear about it. Subscribe to publication.target.published, publication.target.failed, publication.completed and connection.reauth_required, each delivery signed with an HMAC-SHA256 of its body in X-Socialized-Signature.

Upload a file, then publish it within 48 hours; socialized.dev never trims, crops or re-encodes it, so send a file each platform accepts.

A video counts once however many platforms it goes to. Free covers 10 videos a month for 1 brand; Pro is $29 a month for 1,000 videos (a soft limit) and up to 100 brands. The developers page shows the webhooks, retries and errors in full, and links to the quickstart that takes you from an API key to a live post.

Publish it once. See where it went live.

One upload to YouTube, Instagram and Facebook, from the dashboard, the API or the CLI. Free for 10 videos a month, no card needed.