Skip to main content

Social Platform APIs

UniPulse integrates with three social platforms for publishing, analytics, and conversation management. All social API interactions go through the backend -- the frontend never calls platform APIs directly.


Platform Overview

PlatformAPIAuthPublishingMetricsConversations
FacebookMeta Graph API v19+OAuth 2.0 (Facebook Login)YesYesYes
InstagramMeta Graph API v19+OAuth 2.0 (via Facebook)YesYesYes
TikTokContent Publishing APIOAuth 2.0 (Login Kit)YesYesYes (limited)

Facebook & Instagram (Meta Graph API)

Authentication

StepEndpointScopes
OAuth initiationGET /api/v1/auth/oauth/facebookpages_manage_posts, pages_read_engagement, pages_manage_metadata, instagram_basic, instagram_content_publish, instagram_manage_comments, instagram_manage_insights
Token exchangeFacebook OAuth callbackAccess token + page tokens
Token refreshAutomatic via token-refresh queueLong-lived tokens (60 days)

Publishing

PlatformAPI CallContent Types
Facebook PagePOST /{page-id}/feedText, images, videos, links
InstagramPOST /{ig-user-id}/media + POST /{ig-user-id}/media_publishImages, carousels, reels

Metrics Sync

MetricAPISync Queue
Post reach, impressionsGET /{post-id}/insightsanalytics-sync
Post engagement (likes, comments, shares)GET /{post-id}?fields=likes,comments,sharesanalytics-sync
Page follower countGET /{page-id}/insightsanalytics-sync

Conversations

FeatureAPIQueue
Read commentsGET /{post-id}/commentsice-process
Reply to commentsPOST /{comment-id}/repliesvia sendAgentReply()
Read DMsMessenger Platform APIice-process
Webhooks (real-time)Facebook Webhooks (comment, message events)webhook-process

TikTok (Content Publishing API)

Authentication

StepEndpointScopes
OAuth initiationGET /api/v1/auth/oauth/tiktokuser.info.basic, video.publish, video.list, video.insights
Token exchangeTikTok OAuth callbackAccess token + refresh token
Token refreshAutomatic via token-refresh queueRefresh token (90 days)

Publishing

API CallContent Types
Content Publishing API (v2)Videos, images (photo mode)

Metrics Sync

MetricAPI
Video views, likes, comments, sharesTikTok Insights API
Profile follower countTikTok User Info API

Token Management

Social platform tokens are stored encrypted in the SocialAccount model:

FieldStorage
accessTokenAES-256 encrypted (using ENCRYPTION_KEY)
refreshTokenAES-256 encrypted
tokenExpiresAtPlaintext DateTime

Automatic Token Refresh

The token-refresh queue proactively refreshes tokens before they expire:


Rate Limiting

Each platform enforces API rate limits. UniPulse implements per-platform rate limiting to stay within bounds:

PlatformRate LimitStrategy
Facebook/Instagram200 calls per hour per userQueue-based throttling
TikTokVaries by endpointExponential backoff on 429

The publish queue processes one platform at a time and implements backoff when rate limits are hit.


Environment Variables

VariablePlatformRequired For
FACEBOOK_APP_IDFacebook/InstagramOAuth initiation
FACEBOOK_APP_SECRETFacebook/InstagramToken exchange
INSTAGRAM_CALLBACK_URLInstagramOAuth callback
TIKTOK_CLIENT_KEYTikTokOAuth initiation
TIKTOK_CLIENT_SECRETTikTokToken exchange

Cross-Reference