Platform API Connector
Navigate developer portals and obtain API credentials for social/content platforms. Store credentials in Supabase (or any DB) for reuse.
General Pattern
- 1. Create developer app on platform's developer portal
- Configure OAuth redirect URIs and scopes
- Complete OAuth flow (or generate API keys)
- Store credentials in structured format
- Test with a simple API call
Facebook + Instagram
Facebook and Instagram share the same auth system. One Facebook Page Token unlocks both.
Setup
- 1. Go to
developers.facebook.com/apps → Create App → Business type - Add "Facebook Login" product
- In Graph API Explorer (
developers.facebook.com/tools/explorer/):
- Select your app
- Add permissions:
pages_show_list,
pages_read_engagement,
pages_manage_posts,
instagram_basic,
instagram_content_publish
- Generate User Access Token → authorize
- Exchange for long-lived token:
GET /oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={secret}&fb_exchange_token={short_token}
- 4. Get Page Access Token:
GET /me/accounts → find page → copy INLINECODE9 - Get Instagram Business Account ID: INLINECODE10
Store
CODEBLOCK0
Key gotcha
Page Access Tokens from Graph API Explorer are
short-lived unless you exchange the User Token for a long-lived one FIRST, then request Page tokens from the long-lived User Token. Page tokens derived from long-lived user tokens are
permanent (no expiry).
YouTube
Setup
- 1. Go to
console.cloud.google.com → APIs & Services → Credentials - Create OAuth 2.0 Client ID (Web application type)
- Add redirect URI:
http://localhost:8422/callback (or your callback URL) - Enable YouTube Data API v3
- Run local OAuth flow:
CODEBLOCK1
Store
CODEBLOCK2
Key gotcha
If the user previously authorized with limited scopes, the refresh token may not cover
youtube.upload. Must re-authorize with
prompt='consent' to get a new refresh token with full scopes.
Twitter/X
Setup
- 1. Go to INLINECODE15
- Create Project + App (Free tier: 100 posts/month)
- Under Keys and Tokens:
- API Key + Secret (consumer credentials)
- Bearer Token (app-only auth for reading)
- Access Token + Secret (user auth for posting) — generate with Read & Write permissions
- 4. If permissions were Read Only when tokens were generated, regenerate Access Token after changing to Read & Write
Store
CODEBLOCK3
Key gotcha
Free tier caps at
100 posts/month (resets on billing date, not calendar month). No delete or analytics on free tier.
TikTok
Setup
- 1. Go to
developers.tiktok.com → Create App - Add products: Login Kit + Content Posting API
- Configure: app icon (1024x1024), category, ToS URL, Privacy Policy URL, redirect URI
- Submit for review — TikTok requires demo video showing the app in action
- Until approved, use Manual mode (generate content but post manually)
Key gotcha
TikTok Content Posting API requires
full app review with demo video. This takes days to weeks. Plan for Manual mode as interim solution. Login Kit can work in sandbox mode for development.
Credential Storage Pattern
Use a single table with JSONB for flexibility:
CODEBLOCK4
JSONB accommodates different auth shapes per platform without schema changes.
Token Refresh Pattern
CODEBLOCK5
平台API连接器
导航开发者门户并获取社交/内容平台的API凭证。将凭证存储在Supabase(或任何数据库)中以便重复使用。
通用模式
- 1. 在平台的开发者门户上创建开发者应用
- 配置OAuth重定向URI和作用域
- 完成OAuth流程(或生成API密钥)
- 以结构化格式存储凭证
- 通过简单的API调用进行测试
Facebook + Instagram
Facebook和Instagram共享相同的认证系统。一个Facebook主页令牌即可解锁两者。
设置
- 1. 访问 developers.facebook.com/apps → 创建应用 → 商业类型
- 添加Facebook登录产品
- 在Graph API Explorer(developers.facebook.com/tools/explorer/)中:
- 选择你的应用
- 添加权限:pages
showlist、pages
readengagement、pages
manageposts、instagram
basic、instagramcontent_publish
- 生成用户访问令牌 → 授权
- 交换为长期令牌:GET /oauth/access
token?granttype=fb
exchangetoken&client
id={appid}&client
secret={secret}&fbexchange
token={shorttoken}
- 4. 获取主页访问令牌:GET /me/accounts → 找到主页 → 复制 accesstoken
- 获取Instagram商业账户ID:GET /{pageid}?fields=instagrambusinessaccount
存储
json
{
platform: facebook,
credentials: {
app_id: ...,
app_secret: ...,
page_id: ...,
page
accesstoken: ...,
ig
userid: ...
}
}
关键陷阱
来自Graph API Explorer的主页访问令牌是
短期有效的,除非你
先将用户令牌交换为长期令牌,然后从长期用户令牌请求主页令牌。从长期用户令牌派生出的主页令牌是
永久的(无过期时间)。
YouTube
设置
- 1. 访问 console.cloud.google.com → API和服务 → 凭据
- 创建OAuth 2.0客户端ID(Web应用程序类型)
- 添加重定向URI:http://localhost:8422/callback(或你的回调URL)
- 启用YouTube Data API v3
- 运行本地OAuth流程:
python
from googleauthoauthlib.flow import InstalledAppFlow
flow = InstalledAppFlow.fromclientsecrets_file(
credentials.json,
scopes=[https://www.googleapis.com/auth/youtube.upload,
https://www.googleapis.com/auth/youtube.readonly]
)
creds = flow.runlocalserver(port=8422)
creds.token, creds.refresh_token, creds.expiry
存储
json
{
platform: youtube,
credentials: {
client_id: ...,
client_secret: ...,
access_token: ...,
refresh_token: ...,
token_expiry: ...
}
}
关键陷阱
如果用户之前使用有限的作用域进行了授权,刷新令牌可能不涵盖 youtube.upload。必须使用 prompt=consent 重新授权,以获取具有完整作用域的新刷新令牌。
Twitter/X
设置
- 1. 访问 developer.x.com/en/portal/dashboard
- 创建项目 + 应用(免费套餐:每月100条帖子)
- 在密钥和令牌下:
- API密钥 + 密钥(消费者凭证)
- Bearer令牌(仅应用认证,用于读取)
- 访问令牌 + 密钥(用户认证,用于发布)— 使用读取和写入权限生成
- 4. 如果生成令牌时权限为只读,则在更改为读取和写入后重新生成访问令牌
存储
json
{
platform: twitter,
credentials: {
api_key: ...,
api_secret: ...,
bearer_token: ...,
access_token: ...,
access
tokensecret: ...
}
}
关键陷阱
免费套餐限制为
每月100条帖子(按结算日期重置,而非自然月)。免费套餐不支持删除或分析功能。
TikTok
设置
- 1. 访问 developers.tiktok.com → 创建应用
- 添加产品:登录工具包 + 内容发布API
- 配置:应用图标(1024x1024)、分类、服务条款URL、隐私政策URL、重定向URI
- 提交审核 — TikTok要求提供展示应用运行状态的演示视频
- 在审核通过前,使用手动模式(生成内容但手动发布)
关键陷阱
TikTok内容发布API需要
包含演示视频的完整应用审核。这需要数天到数周的时间。建议将手动模式作为临时解决方案。登录工具包可在沙盒模式下用于开发。
凭证存储模式
使用包含JSONB的单个表以实现灵活性:
sql
CREATE TABLE platform_connections (
id UUID PRIMARY KEY DEFAULT genrandomuuid(),
platform TEXT NOT NULL,
account_name TEXT,
credentials JSONB NOT NULL,
scopes TEXT[],
status TEXT DEFAULT active,
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
);
JSONB可以适应不同平台的认证格式,无需修改表结构。
令牌刷新模式
python
async def getvalidtoken(platform: str) -> dict:
conn = await get_connection(platform)
creds = conn[credentials]
if platform == youtube and isexpired(creds.get(tokenexpiry)):
newtoken = refreshgoogletoken(creds[refreshtoken], creds[clientid], creds[clientsecret])
creds[accesstoken] = newtoken
await update_connection(conn[id], creds)
# Facebook主页令牌不会过期(如果从长期用户令牌派生)
# Twitter令牌不会过期
# TikTok令牌24小时后过期 — 使用refresh_token刷新
return creds