YouTube
Upload videos and Shorts to YouTube via the PostPeer API.
Overview
Upload videos and Shorts to YouTube with full metadata control — titles, descriptions, tags, privacy settings, and categories. PostPeer handles YouTube's chunked upload process and OAuth.
Quick Start
1. Connect a YouTube Account
curl https://api.postpeer.dev/v1/connect/youtube \
-H "x-access-key: YOUR_API_KEY"Returns a Google OAuth URL. The user authorizes video upload permissions. See Connect Accounts for the full OAuth flow.
2. Get the Account ID
curl https://api.postpeer.dev/v1/connect/integrations \
-H "x-access-key: YOUR_API_KEY"Find the integration with "platform": "youtube" and note the id.
3. Upload a Video
curl -X POST "https://api.postpeer.dev/v1/posts" \
-H "x-access-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"content": "How to build a social media scheduler",
"platforms": [
{
"platform": "youtube",
"accountId": "yt_789",
"platformSpecificData": {
"title": "How to Build a Social Media Scheduler",
"visibility": "public",
"tags": ["tutorial", "api", "social media"]
}
}
],
"mediaItems": [
{ "type": "video", "url": "https://cdn.example.com/video.mp4" }
],
"publishNow": true
}'import PostPeer from '@postpeer/node';
const client = new PostPeer();
const { data } = await client.posts.create({
body: {
content: 'How to build a social media scheduler',
platforms: [
{
platform: 'youtube',
accountId: 'yt_789',
platformSpecificData: {
title: 'How to Build a Social Media Scheduler',
visibility: 'public',
tags: ['tutorial', 'api', 'social media'],
},
},
],
mediaItems: [{ type: 'video', url: 'https://cdn.example.com/video.mp4' }],
publishNow: true,
},
});from postpeer import PostPeer
with PostPeer() as client:
post = client.posts.create(
content="How to build a social media scheduler",
platforms=[
{
"platform": "youtube",
"accountId": "yt_789",
"platformSpecificData": {
"title": "How to Build a Social Media Scheduler",
"visibility": "public",
"tags": ["tutorial", "api", "social media"],
},
},
],
media_items=[
{"type": "video", "url": "https://cdn.example.com/video.mp4"},
],
publish_now=True,
)Response:
{
"success": true,
"status": "published",
"postId": "post_ghi789",
"platforms": [
{
"platform": "youtube",
"success": true,
"platformPostUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
]
}Platform-Specific Data
Pass this object in platformSpecificData when posting to YouTube.
| Field | Type | Required | Values and constraints | Description |
|---|---|---|---|---|
title | string | No | Length: 0–100 | Video title (max 100 chars, no < or >). Defaults to first 100 chars of content, or "Untitled Video". |
tags | string[] | No | — | Video tags. Total characters across all tags must be ≤500. |
visibility | string | No | public, private, unlisted | Who can see the video. Defaults to "public". Scheduled posts upload as private and flip to this value at publish time. |
madeForKids | boolean | No | — | COPPA compliance flag. Setting to true permanently disables comments, notification bell, personalized ads, end screens, and cards on the video. Defaults to false. |
containsSyntheticMedia | boolean | No | — | AI-generated content disclosure. YouTube is increasingly enforcing this requirement. Defaults to false. |
categoryId | string | No | — | YouTube category ID. Defaults to "22" (People & Blogs). Common values: "1" Film & Animation, "10" Music, "20" Gaming, "22" People & Blogs, "27" Education, "28" Science & Technology. |
firstComment | string | No | Length: 0–10000 | Auto-posted comment after the video goes live. Max 10,000 characters. For publishNow posts: posted immediately after upload. For scheduled posts: posted when the video becomes public. |
Shorts
Upload square or vertical videos up to 3 minutes long, and YouTube will categorize them as Shorts:
curl -X POST "https://api.postpeer.dev/v1/posts" \
-H "x-access-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"content": "Quick API tip! #shorts",
"platforms": [
{
"platform": "youtube",
"accountId": "yt_789",
"platformSpecificData": {
"title": "Quick API Tip",
"visibility": "public"
}
}
],
"mediaItems": [
{ "type": "video", "url": "https://cdn.example.com/short.mp4" }
],
"publishNow": true
}'Supported Formats
| Type | Formats | Maximum size | Maximum duration |
|---|---|---|---|
| Video | MP4 recommended; MOV, MPEG, AVI, WMV, FLV, WebM, 3GPP, ProRes, and HEVC supported | 256 GB | 15 minutes by default; 12 hours for verified accounts |
| Shorts | Same formats as standard video | 256 GB | 3 minutes |
| Thumbnail | JPG or PNG | 2 MB | — |
Pass a thumbnail URL in mediaItems with "thumbnail" field to set a custom thumbnail.
Recommended encoding
| Specification | YouTube recommendation |
|---|---|
| Container | MP4 with no edit lists and the moov atom at the front |
| Video | H.264 High Profile, progressive scan, 4:2:0 chroma subsampling |
| Audio | AAC-LC, 48 kHz |
| Frame rate | Keep the source frame rate; 24, 25, 30, 48, 50, and 60 FPS are common |
| Aspect ratio | 16:9 for standard video; square or vertical for Shorts |
See YouTube's official supported formats, recommended encoding settings, upload limits, and Shorts requirements.