एक ही एपीआई से Node.js के ज़रिए Instagram, TikTok और Facebook पर पोस्ट करें
easyCoexistence के साथ Node.js या TypeScript बैकएंड Instagram, Facebook, TikTok, YouTube और LinkedIn पर हर नेटवर्क के आधिकारिक एपीआई के ज़रिए पोस्ट करता है। खाते एक बार एक होस्टेड लिंक से लॉग इन होते हैं; फिर एक fetch कॉल हर जॉब के लिए TikTok, YouTube और LinkedIn पर ताज़ा टोकन लौटाता है, और हस्ताक्षरित इवेंट टिप्पणियाँ और DM आपके रूट तक पहुँचाते हैं। TypeScript MCP SDK पर बने एजेंट उन्हीं खातों को टूल के रूप में पाते हैं।
TikTok के पब्लिशिंग एंडपॉइंट द्वारा प्रति खाता स्वीकार किए जाने वाले वीडियो पोस्ट, अधिकतम छह प्रति मिनट।
published false और scheduled_publish_time के साथ Facebook पेज पोस्ट कितने आगे तक शेड्यूल की जा सकती है।
नई LinkedIn पोस्ट का URN रखने वाला रिस्पॉन्स हेडर, जो 201 स्टेटस के साथ आता है।
कमेंट बनने, हटने या उसकी दृश्यता बदलने के बाद TikTok comment.update इवेंट कितनी जल्दी भेजता है।
Partner API कनेक्ट लिंक अपने सेशन की समाप्ति से पहले कितनी देर खुला रहता है।
Node.js बैकएंड खाते कैसे कनेक्ट करता है और उनके टोकन कैसे लेता है?
आपका बैकएंड एक कनेक्ट सेशन खोलता है और खाताधारक ब्राउज़र में प्रक्रिया पूरी करता है। /connect-sessions पर POST, जिसमें बियरर टोकन के रूप में आपकी ec_live_ कुंजी हो, tiktok या linkedin जैसा चैनल, redirect_url और आपके ग्राहक के लिए external_ref भेजा जाए, easycoexistence.com पर एक यूआरएल लौटाता है। वहाँ खाताधारक नेटवर्क की अपनी सहमति स्क्रीन पर लॉग इन करता है और status=connected तथा channel_id के साथ आपके redirect_url पर लौटता है; रद्द किए गए प्रयास को उसी लिंक से तब तक दोबारा किया जा सकता है जब तक वह बनने के एक घंटे बाद समाप्त न हो जाए।
हर जॉब फिर GET /channels/{id}?credentials=1 से शुरू होती है। जवाब में एक टोकन होता है जो अभी मान्य है (Instagram और Facebook पर नहीं, जिनके टोकन कभी दिए नहीं जाते), साथ में हर नेटवर्क को चाहिए वाले फ़ील्ड: Instagram और Facebook पर graph_api_base और account_id_on_meta, TikTok पर api_base और business_id, YouTube पर channel_id, LinkedIn पर author_urn और required_headers। हस्ताक्षरित channel.connected, channel.disconnected, channel.removed और channel.suspended इवेंट, जो आपके डैशबोर्ड में सेट किए गए events यूआरएल पर भेजे जाते हैं, आपके ऐप को बताते हैं कि कोई खाता कब बदलता है।
const EC = "https://easycoexistence.com/api/v1";
const KEY = { Authorization: `Bearer ${process.env.EC_API_KEY}` }; // ec_live_...
type Network = "instagram" | "facebook" | "tiktok" | "youtube" | "linkedin";
// A hosted sign-in link for one of your customers on one network
export async function connectLink(customerId: string, channel: Network): Promise<string> {
const r = await fetch(`${EC}/connect-sessions`, {
method: "POST",
headers: { ...KEY, "Content-Type": "application/json" },
body: JSON.stringify({
channel,
redirect_url: "https://app.example.com/connected",
external_ref: customerId,
}),
});
const session = (await r.json()) as { url: string; error?: { message: string } };
if (!r.ok) throw new Error(session.error?.message);
return session.url; // they come back with ?session=...&status=connected&channel_id=...
}
// At the start of every job: the API base and a token that is valid now
export async function credentials(channelId: string) {
const r = await fetch(`${EC}/channels/${channelId}?credentials=1`, { headers: KEY });
const body: any = await r.json(); // the credential fields differ by network
if (!r.ok) throw new Error(body.error.message);
if (!body.credentials.access_token) throw new Error(body.credentials.note);
return body.credentials;
}Node.js से Instagram और Facebook पर पोस्ट कैसे करें?
Instagram एक कंटेनर के ज़रिए पब्लिश होता है। Reel के लिए उसे media_type REELS, video_url और कैप्शन के साथ बनाएँ, उसका status_code FINISHED पढ़े जाने तक पोल करें, फिर creation_id के रूप में कंटेनर id के साथ media_publish कॉल करें। Meta लगभग हर मिनट पोल करने और पाँच मिनट बाद रुक जाने की सलाह देता है; ERROR या EXPIRED का मतलब है कि कंटेनर पब्लिश नहीं होगा, और 24 घंटे तक अप्रकाशित रहने वाला कंटेनर अपने आप समाप्त हो जाता है।
Facebook पेज एक कॉल में /{page-id}/photos पर इमेज यूआरएल और कैप्शन के साथ फ़ोटो लेता है, जबकि टेक्स्ट और लिंक /{page-id}/feed पर जाते हैं। दोनों published false और scheduled_publish_time स्वीकार करते हैं, और समय आने पर Meta खुद पोस्ट पब्लिश करता है, 10 मिनट से 30 दिन आगे तक। टोकन bearer हेडर में जाता है, Graph API वर्शन पहले से graph_api_base के भीतर है, और मीडिया एक सार्वजनिक यूआरएल पर होना चाहिए जिसे Meta डाउनलोड करता है।
type Meta = { graph_api_base: string; access_token: string };
async function graph(c: Meta, path: string, body?: object) {
const r = await fetch(`${c.graph_api_base}/${path}`, {
method: body ? "POST" : "GET",
headers: { Authorization: `Bearer ${c.access_token}`, "Content-Type": "application/json" },
body: body && JSON.stringify(body),
});
const data: any = await r.json();
if (!r.ok) throw new Error(data.error?.message ?? `Graph API ${r.status}`);
return data;
}
export async function postReel(channelId: string, videoUrl: string, caption: string) {
const c = await credentials(channelId);
const ig = c.account_id_on_meta;
const { id } = await graph(c, `${ig}/media`, { media_type: "REELS", video_url: videoUrl, caption });
for (let check = 0; check < 5; check++) {
await new Promise((wake) => setTimeout(wake, 60_000)); // about once a minute, as Meta advises
const { status_code } = await graph(c, `${id}?fields=status_code`);
if (status_code === "FINISHED") return graph(c, `${ig}/media_publish`, { creation_id: id });
if (status_code === "ERROR" || status_code === "EXPIRED") throw new Error(`Reel container ${status_code}`);
}
throw new Error("The Reel is still processing after five minutes");
}
export async function schedulePagePhoto(channelId: string, url: string, caption: string, at: Date) {
const c = await credentials(channelId);
return graph(c, `${c.account_id_on_meta}/photos`, {
url,
caption,
published: false,
scheduled_publish_time: Math.floor(at.getTime() / 1000), // 10 minutes to 30 days ahead
});
}Node.js से LinkedIn पर पोस्ट कैसे करें और YouTube पर अपलोड कैसे करें?
LinkedIn को हर कॉल पर बियरर टोकन के अलावा दो हेडर चाहिए: LinkedIn-Version, जिसमें वह YYYYMM मान हो जो easyCoexistence required_headers में लौटाता है, और X-Restli-Protocol-Version जिसका मान 2.0.0 हो। पोस्ट /rest/posts पर POST है, जिसमें author URN, commentary के रूप में टेक्स्ट, PUBLIC visibility, distribution के रूप में मुख्य फ़ीड और lifecycleState PUBLISHED हो। LinkedIn 201 के साथ जवाब देता है और नई पोस्ट का URN x-restli-id हेडर में रखता है; यूआरएल पथ में रखे गए किसी भी URN को यूआरएल-एन्कोड करना होता है।
YouTube के लिए दो अनुरोध लगते हैं। uploadType=resumable और part=snippet,status के साथ अपलोड एंडपॉइंट पर POST मेटाडेटा भेजता है और अपने Location हेडर में सेशन पता लौटाता है; फ़ाइल के बाइट्स को उस पते पर PUT करने से id के साथ वीडियो रिसोर्स लौटता है। publishAt तारीख के साथ private के रूप में अपलोड करने पर पब्लिशिंग YouTube के अपने शेड्यूलर पर छोड़ दी जाती है, इसलिए उस समय आपकी कोई चीज़ चलानी नहीं पड़ती।
import { readFile } from "node:fs/promises";
export async function postOnLinkedIn(channelId: string, text: string) {
const c = await credentials(channelId);
const r = await fetch(`${c.api_base}/posts`, {
method: "POST",
headers: {
Authorization: `Bearer ${c.access_token}`,
"LinkedIn-Version": c.required_headers["LinkedIn-Version"],
"X-Restli-Protocol-Version": "2.0.0",
"Content-Type": "application/json",
},
body: JSON.stringify({
author: c.author_urn, // urn:li:organization:... or urn:li:person:...
commentary: text,
visibility: "PUBLIC",
distribution: { feedDistribution: "MAIN_FEED", targetEntities: [], thirdPartyDistributionChannels: [] },
lifecycleState: "PUBLISHED",
isReshareDisabledByAuthor: false,
}),
});
if (r.status !== 201) throw new Error(`LinkedIn ${r.status}: ${await r.text()}`);
return r.headers.get("x-restli-id"); // the new post's URN
}
export async function scheduleOnYouTube(channelId: string, file: string, title: string, publishAt: string) {
const c = await credentials(channelId);
const auth = { Authorization: `Bearer ${c.access_token}` };
const start = await fetch(
"https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet,status",
{
method: "POST",
headers: { ...auth, "Content-Type": "application/json; charset=UTF-8", "X-Upload-Content-Type": "video/mp4" },
body: JSON.stringify({
snippet: { title },
status: { privacyStatus: "private", publishAt, selfDeclaredMadeForKids: false },
}),
},
);
const session = start.headers.get("location");
if (!start.ok || !session) throw new Error(`YouTube ${start.status}: ${await start.text()}`);
const done = await fetch(session, {
method: "PUT",
headers: { ...auth, "Content-Type": "video/mp4" },
body: await readFile(file),
});
const video = (await done.json()) as { id: string };
return video.id;
}Node.js रूट में कमेंट और DM कैसे प्राप्त करें?
हर चैनल उस यूआरएल पर भेजता है जो आप PUT /channels/{id}/webhook को देते हैं, और यह कॉल चैनल का signing_secret एक बार लौटाती है। हर डिलीवरी platform, account_id, external_id और entry के साथ POST होती है, और X-EC-Signature हेडर t=<unix>,v1=<hex> के आकार में होता है, जहाँ v1, t, एक बिंदु और कच्चे बॉडी का HMAC-SHA256 है। पार्स करने से पहले बॉडी को टेक्स्ट के रूप में लें, पाँच मिनट से पुराना t अस्वीकार करें, और timingSafeEqual से तुलना करें।
Instagram और Facebook के लिए entry वही Meta वेबहुक entry है जैसी Meta ने भेजी थी: कमेंट और मेंशन के लिए changes, DM के लिए messaging। TikTok के लिए इसमें comment.update इवेंट होता है, जो कमेंट के पाँच मिनट के भीतर भेजा जाता है, जिसमें comment_id और video_id स्ट्रिंग के रूप में होते हैं, ताकि JavaScript इन 64-बिट संख्याओं को गोल न कर दे। हर इवेंट का केवल एक प्रयास होता है और कोई सहेजी हुई कॉपी नहीं रहती, इसलिए तुरंत 204 लौटाएँ और क्यू से प्रोसेस करें।
import { createHmac, timingSafeEqual } from "node:crypto";
const secrets = new Map<string, string>(); // channel id -> signing_secret, kept in your database
export async function forwardEvents(channelId: string, url: string) {
const r = await fetch(`${EC}/channels/${channelId}/webhook`, {
method: "PUT",
headers: { ...KEY, "Content-Type": "application/json" },
body: JSON.stringify({ url }),
});
const body = (await r.json()) as { signing_secret: string; error?: { message: string } };
if (!r.ok) throw new Error(body.error?.message);
secrets.set(channelId, body.signing_secret); // returned only this once
}
function verify(raw: string, header: string | null, secret: string): boolean {
const parts = Object.fromEntries((header ?? "").split(",").map((kv) => kv.split("=", 2)));
const t: string = parts.t ?? "";
const v1: string = parts.v1 ?? "";
if (!/^[0-9]+$/.test(t) || Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
const mac = createHmac("sha256", secret).update(`${t}.${raw}`).digest("hex");
return mac.length === v1.length && timingSafeEqual(Buffer.from(mac), Buffer.from(v1));
}
// POST /hooks/social as a web-standard handler (Next.js, Hono, Bun and others)
export async function POST(req: Request) {
const raw = await req.text(); // the signature covers these exact bytes
const event = JSON.parse(raw); // { platform, account_id, external_id, entry }
const secret = secrets.get(event.account_id);
if (!secret || !verify(raw, req.headers.get("x-ec-signature"), secret)) {
return new Response("invalid signature", { status: 401 });
}
await enqueue(event); // one attempt per event and no retries: acknowledge first
return new Response(null, { status: 204 });
}Node.js से कमेंट और DM का जवाब कैसे दें?
ताज़ा credentials कॉल और इवेंट के id से। Instagram और Facebook पर DM का जवाब /{account-id}/messages पर जाता है, account_id_on_meta का उपयोग करके, प्राप्तकर्ता के रूप में भेजने वाले का id और उनके आख़िरी मैसेज के 24 घंटे के भीतर; पेज messaging_type RESPONSE जोड़ता है, और Instagram अधिकतम 1,000 बाइट टेक्स्ट की अनुमति देता है। कमेंट का सार्वजनिक जवाब Instagram पर /{comment-id}/replies या Facebook पर /{comment-id}/comments पर जाता है, या 7 दिन के भीतर एक निजी जवाब।
TikTok पर बातचीत सार्वजनिक रहती है, क्योंकि TikTok पर DM नहीं होते। Access-Token हेडर, business_id, video_id और comment_id के साथ business/comment/reply/create/ 1,200 अक्षरों तक का जवाब पोस्ट करता है। जवाब के code फ़ील्ड को पढ़ें, जहाँ 0 का मतलब सफलता है, HTTP स्टेटस को नहीं। केवल comment_action insert और comment_type comment वाले इवेंट पर कार्य करें, क्योंकि आपके अपने जवाब भी इवेंट के रूप में आते हैं।
export async function reply(event: any, text: string) {
const c = await credentials(event.account_id);
if (event.platform === "tiktok") {
const e = event.entry.content; // the comment.update event, ids as strings
if (e.comment_action !== "insert" || e.comment_type !== "comment") return; // your replies arrive as "reply"
const r = await fetch(`${c.api_base}/business/comment/reply/create/`, {
method: "POST",
headers: { "Access-Token": c.access_token, "Content-Type": "application/json" },
body: JSON.stringify({ business_id: c.business_id, video_id: e.video_id, comment_id: e.comment_id, text }),
});
const out = (await r.json()) as { code: number; message: string };
if (out.code !== 0) throw new Error(out.message); // 0 is success, whatever the HTTP status
} else if (event.platform === "facebook") {
for (const m of event.entry.messaging ?? []) {
if (!m.message || m.message.is_echo) continue; // only what people sent the Page
await graph(c, `${c.account_id_on_meta}/messages`, {
recipient: { id: m.sender.id },
messaging_type: "RESPONSE", // within 24 hours of their last message
message: { text },
});
}
}
}TikTok पर पोस्ट कैसे करें और TypeScript एजेंट को ये टूल कैसे दें?
दोनों easyCoexistence के MCP सर्वर से होकर जाते हैं, https://easycoexistence.com/api/mcp पर, जो केवल OAuth 2.1 स्वीकार करता है: डायनैमिक क्लाइंट रजिस्ट्रेशन, PKCE के साथ authorization code, एक घंटे तक चलने वाले एक्सेस टोकन और रिफ़्रेश टोकन। @modelcontextprotocol/client, Node 20 और उसके बाद के लिए आधिकारिक TypeScript SDK, के साथ OAuthClientProvider क्लाइंट, टोकन और PKCE verifier रखता है; पहले कनेक्ट पर उपयोगकर्ता लॉग इन के लिए भेजा जाता है और UnauthorizedError फेंका जाता है, और कॉलबैक की क्वेरी के साथ finishAuth इसे पूरा करता है।
TikTok पब्लिशिंग यहीं रहती है, क्योंकि TikTok मीडिया केवल उन यूआरएल प्रीफ़िक्स से डाउनलोड करता है जो टोकन के पीछे के डेवलपर ऐप के लिए सत्यापित हों। publish_tiktok_post आपका HTTPS लिंक लेता है और easyCoexistence के सत्यापित मीडिया रूट का हस्ताक्षरित पता TikTok को देता है, और get_tiktok_publish_status पोस्ट को ट्रैक करता है। वही क्लाइंट एजेंट को खाते के नेटवर्क के हर टूल देता है; पहले list_social_accounts कॉल करें, जिसका account_id Partner API का channel id है।
import { createInterface } from "node:readline/promises";
import { Client, StreamableHTTPClientTransport, UnauthorizedError, type OAuthClientProvider } from "@modelcontextprotocol/client";
const MCP = new URL("https://easycoexistence.com/api/mcp");
const saved: Record<string, any> = {}; // persist this, so the browser sign-in happens once
const provider: OAuthClientProvider = {
redirectUrl: "http://localhost:8090/callback",
clientMetadata: { client_name: "My social agent", redirect_uris: ["http://localhost:8090/callback"] },
state: () => (saved.state = crypto.randomUUID()),
clientInformation: () => saved.client,
saveClientInformation: (info) => { saved.client = info; },
tokens: () => saved.tokens,
saveTokens: (tokens) => { saved.tokens = tokens; },
saveCodeVerifier: (verifier) => { saved.verifier = verifier; },
codeVerifier: () => saved.verifier,
redirectToAuthorization: (url) => console.log("Sign in to easyCoexistence:", url.href),
};
const client = new Client({ name: "my-social-agent", version: "1.0.0" });
const transport = new StreamableHTTPClientTransport(MCP, { authProvider: provider });
try {
await client.connect(transport);
} catch (error) {
if (!(error instanceof UnauthorizedError)) throw error;
const rl = createInterface({ input: process.stdin, output: process.stdout });
const back = new URL(await rl.question("Paste the address you were sent back to: ")).searchParams;
rl.close();
if (back.get("state") !== saved.state) throw new Error("state mismatch");
await transport.finishAuth(back);
await client.connect(new StreamableHTTPClientTransport(MCP, { authProvider: provider }));
}
const result = await client.callTool({
name: "publish_tiktok_post",
arguments: {
account_id: process.env.TIKTOK_CHANNEL_ID, // the Partner API channel id
video_url: "https://cdn.example.com/launch.mp4",
caption: "New drop #behindthescenes",
},
});
console.log(result.content); // a share_id to follow with get_tiktok_publish_statusआम गड़बड़ियाँ
- HMAC को पार्स और दोबारा सीरियलाइज़ किए गए JSON पर गणना करना। हस्ताक्षर कच्चे बॉडी के हर बाइट पर होता है, इसलिए पहले req.text() कॉल करें और बाद में पार्स करें, नहीं तो हर डिलीवरी जाँच में विफल होगी।
- TikTok id को संख्या में बदलना। कमेंट और वीडियो id 64-बिट होते हैं और Number() उन्हें गोल कर देता है, इसलिए जवाब देते समय या कमेंट खोजते समय इवेंट में आने वाली स्ट्रिंग ही रखें।
- रीडायरेक्ट से केवल channel_id रखना। Facebook या LinkedIn लॉग इन एक साथ कई पेज जोड़ सकता है, इसलिए GET /channels?external_ref= से उन्हें सूचीबद्ध करें और हर एक को सहेजें।
- रात के बैच से Messenger या Instagram DM का जवाब देना। व्यक्ति के आख़िरी मैसेज के 24 घंटे बाद भेजना विफल होता है, इसलिए खिड़की खुली रहते हुए इवेंट हैंडलर से जवाब दें।
easyCoexistence Node.js बैकएंड और AI एजेंट को WhatsApp, Instagram, Facebook, TikTok, YouTube, LinkedIn और अन्य चैनलों पर ग्राहकों तक पहुँच देता है, हर एक उसके आधिकारिक एपीआई के ज़रिए। Partner API से खाते कनेक्ट करें, ताज़ा टोकन और हस्ताक्षरित इवेंट लें, और TypeScript एजेंट MCP सर्वर से काम करें, हर कनेक्शन 24/7 निगरानी में। प्रति कनेक्शन प्रति माह US$ 9 से US$ 0.75 तक, जैसे-जैसे कनेक्शन बढ़ते हैं कीमत घटती है, और पहले 3 दिन मुफ़्त।
अक्सर पूछे जाने वाले सवाल
क्या इन एपीआई को Node से कॉल करने के लिए मुझे SDK चाहिए?
नहीं। Partner API और नेटवर्क के एपीआई सादे HTTPS हैं, इसलिए Node 18 और उसके बाद का global fetch इन्हें कवर करता है। @modelcontextprotocol/client केवल MCP टूल के लिए चाहिए, जिनमें TikTok पब्लिशिंग भी शामिल है।
TikTok पब्लिशिंग MCP सर्वर से क्यों होकर जाती है?
TikTok वीडियो और फ़ोटो केवल उस डोमेन या यूआरएल प्रीफ़िक्स से डाउनलोड करता है जो डेवलपर ऐप के लिए सत्यापित हो, और वह ऐप easyCoexistence का है। publish_tiktok_post आपकी HTTPS फ़ाइल को उस सत्यापित पते से परोसता है, इसलिए आपके अपने डोमेन को सत्यापन की ज़रूरत नहीं।
क्या एक लॉग इन से कई Facebook या LinkedIn पेज कनेक्ट हो सकते हैं?
हाँ। हर पेज, और LinkedIn पर सदस्य की अपनी प्रोफ़ाइल, अपना चैनल और अपना कनेक्शन बन जाता है। रीडायरेक्ट पहला channel_id लेकर आता है, और GET /channels?external_ref= उन सबकी सूची देता है।
Node.js के लिए easyCoexistence की लागत कितनी है?
प्रति कनेक्शन प्रति माह US$ 9 से US$ 0.75 तक, जैसे-जैसे कनेक्शन बढ़ते हैं कीमत घटती है, और हर नेटवर्क पर यही दर। Partner API और MCP कनेक्टर इसी में शामिल हैं, बिना सीट शुल्क के, और पहले 3 दिन मुफ़्त हैं।
पढ़ना जारी रखें
दो मिनट में अपना पहला चैनल कनेक्ट करें।
किसी प्लैटफ़ॉर्म की समीक्षा का इंतज़ार नहीं। WhatsApp, Instagram, TikTok या कोई और चैनल कनेक्ट करें, फिर अपने AI से पोस्ट करने, जवाब देने या रिपोर्ट बनाने को कहें और उसे काम करते देखें।
- 3 दिन मुफ़्त
- कभी भी रद्द करें
- सिर्फ़ आधिकारिक एपीआई
- 24/7 निगरानी
इस तारीख को सत्यापित