Token导航 LogoToken导航TokenDH.com
开发规范敏感数据github未标认证来源可访问clear审计异常

social-media-api-best-practicessocial media API 最佳实践

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

1,327

周安装

57

GitHub Stars

1

下载量

465
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:social-media-api-best-practices(social media API 最佳实践)
来源仓库:https://github.com/getlate-dev/social-media-api-best-practices
仓库路径:skills/social-media-api-best-practices
安装命令:
npx skills add https://github.com/getlate-dev/social-media-api-best-practices --skill social-media-api-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/getlate-dev/social-media-api-best-practices --skill social-media-api-best-practices

简介

social-media-api-best-practices 用于辅助 API 设计、接口文档生成和前后端联调说明。

  • 适合梳理 endpoint、整理错误码或生成集成说明文档。
  • 通过 GitHub 仓库安装,支持 Codex、Claude 等平台使用。
  • 涉及接口定义时应以现有代码或样例为依据,避免凭空补充字段。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Social Media API Best Practices

Battle-tested patterns from scheduling 1M+ posts across 13 platforms.


1. Authentication Patterns

OAuth 2.0 Platforms

Instagram (Meta Graph API)

  • Two-step token exchange: short-lived (1 hour) → long-lived (60 days)
  • Use auth_type: 'rerequest' to force permission re-prompts
  • Exchange endpoint: ig_exchange_token grant type
  • Scopes: instagram_business_basic, instagram_business_content_publish, instagram_business_manage_messages, instagram_business_manage_comments, instagram_business_manage_insights

Twitter/X (PKCE Required)

  • PKCE with S256 code challenge is mandatory
  • Embed code verifier in state: ${state}-cv_${codeVerifier}
  • Scopes: tweet.read, tweet.write, users.read, offline.access, media.write, dm.read, dm.write
  • Access token: 2 hours, refresh token: long-lived
function generateCodeVerifier(): string {
  return crypto.randomBytes(32).toString('base64url');
}

function generateCodeChallenge(verifier: string): string {
  return crypto.createHash('sha256').update(verifier).digest('base64url');
}

function extractCodeVerifierFromState(state: string): string {
  const match = state.match(/-cv_(.+)$/);
  return match ? match[1] : '';
}

TikTok

  • Full UX compliance required for API audit approval
  • Must show: privacy_level selector, comment/duet/stitch toggles
  • Commercial content disclosure mandatory
  • Scopes: user.info.basic, user.info.profile, user.info.stats, video.publish, video.upload, video.list

LinkedIn

  • Always include header: X-RestLi-Protocol-Version: 2.0.0
  • API version header: LinkedIn-Version: 202511 (some endpoints use 202505 or 202401)
  • Access token: 60 days, refresh token: 365 days
  • Supports both personal (urn:li:person:) and organization (urn:li:organization:) posts
  • Personal scopes: openid, profile, r_basicprofile, email, w_member_social, w_member_social_feed, r_member_postAnalytics, r_member_profileAnalytics, r_1st_connections_size
  • Organization scopes: w_organization_social, w_organization_social_feed, r_organization_admin, r_organization_social, r_organization_social_feed, r_organization_followers

YouTube

  • Requires access_type=offline AND prompt=consent for refresh tokens
  • Supports both user channels and brand accounts
  • Scopes: youtube.upload, youtube, youtube.force-ssl, yt-analytics.readonly

Facebook

  • Page access tokens are separate from user tokens
  • Exchange user token for page token via /me/accounts
  • Supports scheduled publishing via scheduled_publish_time
  • Scopes: pages_manage_posts, pages_show_list, pages_read_engagement, pages_manage_engagement, pages_read_user_content, business_management, pages_messaging

Threads

  • Similar to Instagram (Meta), 2-step token exchange
  • Use th_exchange_token grant type
  • Scopes: threads_basic, threads_content_publish, threads_manage_replies, threads_read_replies, threads_manage_insights, threads_delete

Pinterest

  • OAuth 2.0 with refresh tokens
  • Scopes: pins:read, pins:write, boards:read, boards:write, user_accounts:read

Google Business Profile

  • Google OAuth with scopes: business.manage, userinfo.profile, userinfo.email
  • Uses My Business v4 API

Reddit

  • OAuth with duration=permanent for long-lived tokens
  • Strict user-agent requirement - Reddit enforces descriptive user agents
  • Scopes: identity, submit, read, mysubreddits, privatemessages, history, edit, vote
const headers = {
  'User-Agent': 'YourApp/1.0 by /u/YourUsername'
};

Non-OAuth Platforms

Bluesky (AT Protocol)

  • No traditional OAuth - uses DIDs (Decentralized Identifiers)
  • Authentication via accessJwt + refreshJwt from AT Protocol
  • PDS (Personal Data Server) resolution required
  • Auto-refresh on ExpiredToken error
// Bluesky authentication
const session = await agent.login({
  identifier: 'user.bsky.social',
  password: 'app-password'
});
// session contains: accessJwt, refreshJwt, did, handle

Snapchat

  • Basic auth, allowlist-only (requires Snapchat dev team approval)
  • Limited public API - profile API focus
  • Scopes: snapchat-profile-api

Telegram

  • Bot token only - no OAuth flow
  • Token format: BOT_ID:SECRET
  • No user authentication, bot must be added to chat/channel

2. Rate Limiting Strategies

Platform-Specific Limits

PlatformKey LimitStrategy
Instagram100 posts/day per accountQueue and spread
TikTok5 pending uploads/24hWait for processing
Twitter3-tier limits (app + user + endpoint)Check all three
LinkedInGenerous general, strict bulkBatch carefully
YouTubeDaily upload quota per channelMonitor quota
Reddit60 requests/minuteRespect headers
ThreadsAggressive rate limitingFails fast

Twitter's Three-Tier Rate Limits

Twitter has THREE levels of limits - check all:

  1. App-level 24-hour limit (most restrictive)
  2. User-level 24-hour limit
  3. Endpoint-specific rate limit
function parseRateLimitHeaders(headers: Headers) {
  return {
    // Endpoint limits
    remaining: parseInt(headers.get('x-rate-limit-remaining') || '0'),
    reset: parseInt(headers.get('x-rate-limit-reset') || '0'),
    // App-level 24h limits
    appRemaining: parseInt(headers.get('x-app-limit-24hour-remaining') || '0'),
    appReset: parseInt(headers.get('x-app-limit-24hour-reset') || '0'),
    // User-level 24h limits
    userRemaining: parseInt(headers.get('x-user-limit-24hour-remaining') || '0'),
    userReset: parseInt(headers.get('x-user-limit-24hour-reset') || '0'),
  };
}

Exponential Backoff Pattern

async function withRetry<T>(
  fn: () => Promise<T>,
  maxRetries = 3,
  baseDelay = 5000
): Promise<T> {
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
    try {
      return await fn();
    } catch (error) {
      if (!isRetryableError(error) || attempt === maxRetries) throw error;
      const delay = Math.min(baseDelay * Math.pow(2, attempt), 30000);
      await sleep(delay);
    }
  }
  throw new Error('Max retries exceeded');
}

function isRetryableError(error: any): boolean {
  const status = error.status || error.statusCode;
  return [429, 500, 502, 503].includes(status);
}

3. Media Requirements

Complete Platform Limits

PlatformMax ImageMax VideoAspect RatioSpecial
Instagram8MB100MB stories, 300MB reels4:5 to 1.91:1 feed, 9:16 stories10 carousel items
TikTok20MB4GB, 3s-10min9:16 strict35 photo carousel
Twitter5MB512MB, 2min 20sFlexible1-4 images
LinkedIn8MB5GBFlexible20 image carousel
YouTube2MB thumbnail256GB16:9 preferredResumable upload
Facebook10MB4GBFlexible10 multi-image
Threads8MB1GB, 5min9:16 vertical10 carousel
Pinterest32MB2GBFlexibleRequires cover image
Bluesky1MB50MB, 3minFlexibleAT Protocol
Snapchat20MB500MB9:16AES encryption
Google Business5MBN/AFlexibleImages only
Reddit20MBN/AFlexibleVia URL
Telegram10MB50MBFlexible4096 char limit

Golden Rule: Stream Large Files

Never load entire files into memory:

// BAD - loads entire file into memory
const buffer = await fetch(url).then(r => r.arrayBuffer());

// GOOD - streams directly
const response = await fetch(url);
await uploadToPlatform(response.body); // Pass the stream

Problematic Media Sources

These hosts return HTML or timeout instead of direct media:

const PROBLEMATIC_HOSTS = [
  'drive.google.com',
  'docs.google.com',
  'dropbox.com',
  'onedrive.live.com',
  '1drv.ms'
];

// Solution: Re-host to your own storage first
if (PROBLEMATIC_HOSTS.some(h => url.includes(h))) {
  url = await reHostToStorage(url);
}

Dropbox URL Fix

function fixDropboxUrl(url: string): string {
  if (url.includes('dropbox.com') && url.includes('dl=0')) {
    return url.replace('dl=0', 'dl=1');
  }
  return url;
}

4. Video Upload Patterns

Chunked Upload (Twitter)

async function chunkedUpload(videoBuffer: Buffer, mediaType: string) {
  const CHUNK_SIZE = 4 * 1024 * 1024; // 4MB chunks

  // INIT
  const initRes = await api.post('/media/upload', {
    command: 'INIT',
    total_bytes: videoBuffer.length,
    media_type: mediaType
  });
  const mediaId = initRes.media_id_string;

  // APPEND chunks
  for (let i = 0; i < Math.ceil(videoBuffer.length / CHUNK_SIZE); i++) {
    const chunk = videoBuffer.slice(i * CHUNK_SIZE, (i + 1) * CHUNK_SIZE);
    await api.post('/media/upload', {
      command: 'APPEND',
      media_id: mediaId,
      media: chunk.toString('base64'),
      segment_index: i
    });
  }

  // FINALIZE
  await api.post('/media/upload', {
    command: 'FINALIZE',
    media_id: mediaId
  });

  // Poll for processing
  await pollProcessingStatus(mediaId);

  return mediaId;
}

Resumable Upload (YouTube)

YouTube supports resumable uploads for reliability with large files. Use the youtube-chunked-upload module or implement the resumable upload protocol.

Processing Status Polling

async function pollProcessingStatus(mediaId: string, maxWaitMs = 300000) {
  const startTime = Date.now();

  while (Date.now() - startTime < maxWaitMs) {
    const status = await api.get(`/media/upload?command=STATUS&media_id=${mediaId}`);

    if (status.processing_info?.state === 'succeeded') return;
    if (status.processing_info?.state === 'failed') {
      throw new Error(status.processing_info.error?.message || 'Processing failed');
    }

    const checkAfter = (status.processing_info?.check_after_secs || 5) * 1000;
    await sleep(checkAfter);
  }

  throw new Error('Processing timeout');
}

5. Error Handling

Error Categorization

type ErrorType = 'refresh-token' | 'retry' | 'user-error';

function categorizeError(platform: string, error: any): ErrorType {
  if (isTokenError(error)) return 'refresh-token';
  if (isTemporaryError(error)) return 'retry';
  return 'user-error';
}

Instagram Error Codes

CodeMeaningAction
2207001Spam detectedUser error
2207003Media download timeoutRetry
2207004Image too large (>8MB)Compress
2207006Media not foundUser error
2207026Unsupported video formatRe-encode
2207042100 posts/day exceededWait 24h
2207050User restrictedUser error
2207051Blocked (but may have posted!)Verify
2207052Media fetch failedUse direct URLs

The Instagram 2207051 Edge Case

Instagram's anti-spam sometimes returns "blocked" but actually publishes:

async function handleInstagram2207051(accountId: string) {
  await sleep(5000);

  const recentMedia = await getRecentMedia(accountId);
  const justPosted = recentMedia.find(m =>
    Date.now() - new Date(m.timestamp).getTime() < 60000
  );

  if (justPosted) {
    return { success: true, postId: justPosted.id };
  }
  throw new Error('Post actually failed');
}

TikTok Error Codes

CodeMeaningAction
access_token_invalidToken expiredRefresh
scope_not_authorizedMissing permissionReconnect
rate_limit_exceededToo many requestsRetry
spam_risk_*Content flaggedUser error
file_format_check_failedInvalid formatUser error
unaudited_client_can_only_post_to_privateDev modePrivate only

Twitter/X Error Codes

CodeMeaningAction
invalid_grantToken revokedReconnect
usage-cappedRate limitedRetry
duplicateSame content existsUser error
186Tweet too longUser error

Bluesky Error Codes

CodeMeaningAction
ExpiredTokenJWT expiredAuto-refresh
InvalidTokenBad tokenReconnect
XRPCNotSupportedApp password lacks DMUse full auth

Reddit Error Codes

CodeMeaningAction
invalid tokenExpiredRefresh
not allowed to submitSubreddit restrictionUser error
RATELIMITToo fastRetry with delay
NO_LINKSLinks not allowedUser error

Telegram Error Codes

CodeMeaningAction
message too long>4096 charsTruncate
chat not foundInvalid chat IDUser error
bot was blockedUser blocked botUser error

6. Platform Quirks

JavaScript Large Integer IDs (Instagram/Facebook)

Instagram IDs exceed MAX_SAFE_INTEGER (17+ digits):

function safeJsonParse(text: string) {
  // Wrap large integers in quotes before parsing
  const safe = text.replace(/"id"\s*:\s*(\d{15,})/g, '"id":"$1"');
  return JSON.parse(safe);
}

Twitter Character Counting

function countTwitterCharacters(text: string): number {
  let count = 0;

  // URLs always count as 23 characters
  const urlRegex = /https?:\/\/[^\s]+/g;
  const urls = text.match(urlRegex) || [];
  const textWithoutUrls = text.replace(urlRegex, '');

  count += urls.length * 23;

  // Emojis and CJK count as 2
  for (const char of textWithoutUrls) {
    count += char.match(/[\u{1F600}-\u{1F64F}]|[\u4e00-\u9fff]/u) ? 2 : 1;
  }

  return count;
}

Twitter Character Limits by Tier

TierLimit
Free280
Premium4,000
Premium+25,000

LinkedIn Text Escaping

Reserved characters: | {} [] () < > # \ * _ ~

Note: @ is deliberately NOT escaped to avoid \@ showing in posts. URN mentions @[Name](urn:li:person:ID) and hashtags #tag are preserved automatically.

function escapeLinkedInText(text: string): string {
  // Reserved chars (excluding @ to preserve readability)
  const reserved = /[\|\{\}\[\]\(\)\<\>\#\\\*\_\~]/;

  let output = '';
  let i = 0;

  while (i < text.length) {
    // Preserve URN mentions: @[Display Name](urn:li:person:ID)
    if (text[i] === '@' && text[i + 1] === '[') {
      const closeBracket = text.indexOf(']', i + 2);
      if (closeBracket !== -1 && text.substring(closeBracket + 1, closeBracket + 9) === '(urn:li:') {
        const closeParen = text.indexOf(')', closeBracket + 9);
        if (closeParen !== -1) {
          output += text.substring(i, closeParen + 1);
          i = closeParen + 1;
          continue;
        }
      }
    }

    // Preserve hashtags: #word
    if (text[i] === '#' && /[a-zA-Z0-9_]/.test(text[i + 1] || '')) {
      output += text[i++];
      while (i < text.length && /[a-zA-Z0-9_]/.test(text[i])) {
        output += text[i++];
      }
      continue;
    }

    // Escape reserved characters
    output += reserved.test(text[i]) ? '\\' + text[i] : text[i];
    i++;
  }

  return output;
}

TikTok UX Compliance Requirements

TikTok requires full UX compliance for API audit:

  • User must manually select privacy level (no defaults)
  • Must show comment/duet/stitch toggles
  • Commercial content disclosure with user confirmation
  • Content preview before upload
  • Express consent declaration

Reddit User-Agent Requirement

Reddit strictly enforces descriptive user agents:

// BAD - will be blocked
headers['User-Agent'] = 'axios/1.0';

// GOOD - descriptive format
headers['User-Agent'] = 'MyApp/1.0 (by /u/developer_username)';

Telegram HTML Subset

Only these HTML tags are supported:

<b>, <strong>       <!-- bold -->
<i>, <em>           <!-- italic -->
<u>                 <!-- underline -->
<s>, <strike>, <del><!-- strikethrough -->
<code>              <!-- monospace -->
<pre>               <!-- code block -->
<a href="...">      <!-- link -->
<tg-spoiler>        <!-- spoiler -->
<blockquote>        <!-- quote -->

7. Special Protocols

AT Protocol (Bluesky)

Bluesky uses AT Protocol, not OAuth:

Key Concepts:

  • DID (Decentralized Identifier): User's permanent ID (e.g., did:plc:abc123)
  • PDS (Personal Data Server): Where user data lives
  • Handle: Human-readable name (e.g., user.bsky.social)

Rich Text Facets:

Mentions and links use byte-offset positioning:

function createFacets(text: string): Facet[] {
  const facets: Facet[] = [];
  const encoder = new TextEncoder();

  // Find mentions
  const mentionRegex = /@([a-zA-Z0-9.-]+)/g;
  let match;

  while ((match = mentionRegex.exec(text)) !== null) {
    const beforeText = text.slice(0, match.index);
    const byteStart = encoder.encode(beforeText).length;
    const byteEnd = byteStart + encoder.encode(match[0]).length;

    facets.push({
      index: { byteStart, byteEnd },
      features: [{
        $type: 'app.bsky.richtext.facet#mention',
        did: await resolveDid(match[1])
      }]
    });
  }

  return facets;
}

Snapchat AES-256-CBC Encryption

Snapchat requires media encryption before upload:

import crypto from 'crypto';

function encryptForSnapchat(buffer: Buffer): {
  encrypted: Buffer;
  key: string;
  iv: string;
} {
  const key = crypto.randomBytes(32); // 256 bits
  const iv = crypto.randomBytes(16);  // 128 bits

  const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
  const encrypted = Buffer.concat([
    cipher.update(buffer),
    cipher.final()
  ]);

  return {
    encrypted,
    key: key.toString('base64'),
    iv: iv.toString('base64')
  };
}

8. Quick Debugging Checklist

When a post fails:

  1. Check token validity - Is the access token expired?
  2. Check rate limits - Hit daily/hourly limits?
  3. Check media URL - Can the platform fetch it directly?
  4. Check media specs - Right format, size, dimensions, aspect ratio?
  5. Check the 2207051 case - Did it post despite the error?
  6. Check account status - Is the account restricted?
  7. Check subreddit rules - (Reddit) Links allowed? Flair required?
  8. Check user-agent - (Reddit) Descriptive enough?
  9. Check bot permissions - (Telegram) Bot in chat with send rights?

9. Recommended Architecture

your-app/
├── lib/
│   ├── platforms/
│   │   ├── base.ts           # Abstract base class
│   │   ├── instagram.ts
│   │   ├── tiktok.ts
│   │   ├── twitter.ts
│   │   ├── bluesky.ts        # AT Protocol
│   │   ├── snapchat.ts       # With encryption
│   │   └── ...
│   ├── utils/
│   │   ├── rate-limiter.ts
│   │   ├── media-handler.ts
│   │   ├── error-mapper.ts
│   │   └── encryption.ts     # For Snapchat
│   └── queue/
│       └── scheduler.ts

10. Platform Comparison Matrix

FeatureInstagramTikTokTwitterLinkedInYouTubeFacebookThreadsPinterestBlueskySnapchatGBPRedditTelegram
OAuth2-stepStandardPKCEStandardGoogleStandard2-stepBasicAT ProtoBasicGoogleStandardBot Token
Token Life60d2y+2h+refresh365d refresh1y60d+60dN/AAutoN/A1yPermanentN/A
VideoYesYesYesYesYesYesYesYesYesYesNoNoYes
Carousel1035420No1010No4NoNoGalleryAlbum 10
SchedulingAPIDraftNoAPIAPIAPIAPINoAPINoNoNoNo
DMsYesNoYesYesNoYesNoNoYesYesNoYesYes
AnalyticsYesYesYesYesYesYesYesYesNoNoLimitedNoLimited

About This Guide

This guide is maintained by Late, built from real patterns learned while scheduling 1M+ posts across all 13 platforms.

Every error code, edge case, and quirk documented here comes from production experience. The Instagram 2207051 gotcha? We discovered it after hours of debugging. The Snapchat encryption requirement? Learned the hard way.

Building a social media app? If you'd rather not implement and maintain all these integrations yourself, Late's API handles the complexity for you: OAuth, media processing, rate limits, error handling, and scheduling across all 13 platforms with a single integration.


*Maintained by Late - Social Media Scheduling API for Developers*

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenCode

30.95%
按下载量换算144

Claude Code

21.85%
按下载量换算102

Gemini CLI

16.92%
按下载量换算79

Codex

13.33%
按下载量换算62

Antigravity

8.34%
按下载量换算39

Cursor

3.11%
按下载量换算14

安全审计

Gen Agent Trust Hub

未通过

Socket

通过

Snyk

可疑

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills