लॉग इनमुफ़्त ट्रायल शुरू करें
easyCoexistence आधिकारिक एपीआई

Python और Node.js में TikTok एपीआई: काम करने वाले उदाहरण

TikTok का कारोबारी एपीआई सादे HTTPS अनुरोधों के ज़रिए Python या Node.js से काम करता है: हर कॉल https://business-api.tiktok.com/open_api/v1.3 पर भेजें, खाते का टोकन Access-Token हेडर में और उसका open_id business_id के रूप में डालें। TikTok ज़्यादातर कॉल का जवाब HTTP 200 और code फ़ील्ड के साथ देता है, जिसमें सफलता पर 0 होता है, इसलिए उसे जाँचें और 40100 पर 5 मिनट रुकें।

easyCoexistence Claude, ChatGPT या आपके अपने कोड को वही TikTok काम टूल के रूप में देता है: publish_tiktok_post और reply_to_comment से लेकर get_social_insights तक, और get_social_credentials या Partner एपीआई के ज़रिए आपकी स्क्रिप्ट को ताज़ा टोकन देता है।

HTTP 200

ज़्यादातर TikTok जवाबों का स्टेटस, गड़बड़ियों समेत; केवल बॉडी में code 0 का मतलब है कि कॉल सफल रही।

40100

थ्रॉटल की गई कॉल का कोड: TikTok प्रति मिनट सीमा के बाद 5 मिनट के ठहराव और प्रतिदिन की सीमा के बाद 00:00 UTC पर वापस आने को कहता है।

5xx

सर्वर गड़बड़ियाँ, जिनके बाद TikTok लगभग 5 मिनट रुककर दोबारा कॉल करने का सुझाव देता है।

Final /

पाथ स्लैश पर खत्म होते हैं; TikTok के अनुसार /tt_user/oauth2/refresh_token बिना स्लैश के 404 page not found का कारण है।

3 languages

TikTok के कारोबारी एपीआई SDK में Python, JavaScript और Java हैं, और उसकी एंडपॉइंट सूची में कोई /business/ एंडपॉइंट नहीं है।

HMAC-SHA256

हर वेबहुक के Tiktok-Signature हेडर में सिग्नेचर होता है, जो टाइमस्टैम्प, एक बिंदु और बॉडी पर बनता है, और ऐप सीक्रेट से बनी कुंजी से जाँचा जाता है।

हर TikTok API कॉल को किन पाँच चीज़ों की ज़रूरत होती है?

काम चाहे जो भी हो, ज़रूरत हमेशा एक जैसी होती है:

  • बेस यूआरएल https://business-api.tiktok.com/open_api/v1.3, जिसके साथ पाथ स्लैश पर खत्म होता है, जैसे /business/video/list/।
  • खाते का एक्सेस टोकन Access-Token हेडर में, जिसे उसके 24 घंटे खत्म होने से पहले नवीनीकृत करें।
  • business_id, यानी खाते का open_id: GET में क्वेरी स्ट्रिंग में, POST में JSON बॉडी में।
  • GET पर सूची और ऑब्जेक्ट पैरामीटर, जैसे fields और filters, JSON टेक्स्ट के रूप में भेजें: fields=["item_id","caption"]।
  • जवाब में code की जाँच करें, क्योंकि TikTok 40002 या 40100 जैसी गड़बड़ियाँ HTTP 200 के साथ भेजता है, और data तभी आता है जब code 0 हो।

Python में TikTok के गड़बड़ी-लिफ़ाफ़े को कैसे संभालें?

एक छोटा क्लाइंट, जो हर मेथड की जगह business_id रखता है, code 0 होने पर डेटा लौटाता है और अन्यथा TikTokError उठाता है। थ्रॉटल की गई कॉल को TikTok के 5 मिनट के ठहराव के बाद दोबारा भेजता है, क्योंकि 40100 का मतलब है कि TikTok ने कॉल ठुकराई, और 5xx को सिर्फ़ GET पर दोहराता है, क्योंकि सर्वर गड़बड़ी पर खत्म हुआ पब्लिश फिर भी TikTok तक पहुँचा हो सकता है। इसके लिए requests चाहिए, और आगे के Python उदाहरण इसी को दोबारा इस्तेमाल करते हैं:

Python: a TikTok client that reads the envelope
import json
import os
import time

import requests

API = "https://business-api.tiktok.com/open_api/v1.3"


class TikTokError(Exception):
    def __init__(self, code, message, request_id):
        super().__init__(f"TikTok {code}: {message} (request_id {request_id})")
        self.code = code


class TikTok:
    """One TikTok account: its access token and its business_id, the open_id."""

    def __init__(self, access_token, business_id, pause=300):
        self.http = requests.Session()
        self.http.headers["Access-Token"] = access_token
        self.business_id = business_id
        self.pause = pause  # TikTok's advice after a 40100 or a 5xx: about 5 minutes

    def call(self, method, path, params=None, body=None, tries=3):
        for attempt in range(1, tries + 1):
            if method == "GET":
                query = {"business_id": self.business_id}
                for key, value in (params or {}).items():
                    is_json = isinstance(value, (list, dict))
                    query[key] = json.dumps(value, separators=(",", ":")) if is_json else value
                res = self.http.get(f"{API}/{path}", params=query, timeout=30)
            else:
                payload = {"business_id": self.business_id, **(body or {})}
                res = self.http.post(f"{API}/{path}", json=payload, timeout=30)
            if res.status_code >= 500 and method == "GET" and attempt < tries:
                time.sleep(self.pause)  # a POST is not repeated: it may have reached TikTok
                continue
            res.raise_for_status()  # a 4xx: a wrong path or method, such as a missing final slash
            answer = res.json()
            if answer.get("code") == 0:
                return answer.get("data") or {}
            if answer.get("code") == 40100 and attempt < tries:
                time.sleep(self.pause)  # throttled: TikTok refused the call, so repeating it is safe
                continue
            raise TikTokError(answer.get("code"), answer.get("message"), answer.get("request_id"))


tt = TikTok(os.environ["TIKTOK_ACCESS_TOKEN"], os.environ["TIKTOK_BUSINESS_ID"])

Node.js में इसे कैसे संभालें?

वही क्लाइंट Node.js 18 और उसके बाद के संस्करणों में मौजूद built-in fetch पर चलता है, जिसे कुछ इंस्टॉल नहीं करना पड़ता। यह GET के लिए सूची पैरामीटर को JSON में एन्कोड करता है, POST के लिए business_id को बॉडी में डालता है, और गड़बड़ी पर TikTok का code बनाए रखता है, ताकि कॉल करने वाला 40102 या 40105 (टोकन की समस्या) को 40001 (अनुमति की कमी) से अलग पहचान सके:

Node.js: the same client on the built-in fetch
const API = "https://business-api.tiktok.com/open_api/v1.3";
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

class TikTokError extends Error {
  constructor(code, message, requestId) {
    super("TikTok " + code + ": " + message + " (request_id " + requestId + ")");
    this.code = code;
  }
}

// One TikTok account: its access token and its business_id, the open_id.
class TikTok {
  constructor(accessToken, businessId, pauseMs = 300000) {
    this.accessToken = accessToken;
    this.businessId = businessId;
    this.pauseMs = pauseMs; // TikTok's advice after a 40100 or a 5xx: about 5 minutes
  }

  async call(method, path, { params = {}, body = {} } = {}, tries = 3) {
    for (let attempt = 1; ; attempt++) {
      const url = new URL(API + "/" + path);
      const init = { method, headers: { "Access-Token": this.accessToken } };
      if (method === "GET") {
        url.searchParams.set("business_id", this.businessId);
        for (const [key, value] of Object.entries(params)) {
          url.searchParams.set(key, typeof value === "object" ? JSON.stringify(value) : String(value));
        }
      } else {
        init.headers["Content-Type"] = "application/json";
        init.body = JSON.stringify({ business_id: this.businessId, ...body });
      }
      const res = await fetch(url, init);
      if (res.status >= 500 && method === "GET" && attempt < tries) {
        await sleep(this.pauseMs); // a POST is not repeated: it may have reached TikTok
        continue;
      }
      if (!res.ok) throw new Error("HTTP " + res.status + " on " + path + ": check the path, its final slash and the method");
      const answer = await res.json();
      if (answer.code === 0) return answer.data ?? {};
      if (answer.code === 40100 && attempt < tries) {
        await sleep(this.pauseMs); // throttled: TikTok refused the call, so repeating it is safe
        continue;
      }
      throw new TikTokError(answer.code, answer.message, answer.request_id);
    }
  }
}

const tt = new TikTok(process.env.TIKTOK_ACCESS_TOKEN, process.env.TIKTOK_BUSINESS_ID);

URL से वीडियो कैसे पब्लिश करें और उसकी स्थिति कैसे जाँचें?

POST /business/video/publish/ को video_url और post_info के साथ भेजें, फिर share_id को publish_id के रूप में डालकर /business/publish/status/ से स्थिति बार-बार जाँचें। लूप FAILED पर TikTok के कारण के साथ रुकता है, और PUBLISH_COMPLETE पर post_ids आने तक इंतज़ार करता है, जिसमें TikTok के अनुसार तीन मिनट तक लग सकते हैं। video_url आपके ऐप के लिए सत्यापित डोमेन या यूआरएल प्रीफ़िक्स पर होना चाहिए:

Publish a video and wait until it is public: Python, then Node.js
# Python
def wait_until_live(tt, share_id, interval=30, give_up_after=7200):
    deadline = time.time() + give_up_after
    while time.time() < deadline:
        status = tt.call("GET", "business/publish/status/", params={"publish_id": share_id})
        if status["status"] == "FAILED":
            raise RuntimeError(f"TikTok did not publish {share_id}: {status.get('reason')}")
        if status["status"] == "PUBLISH_COMPLETE" and status.get("post_ids"):
            return status["post_ids"]
        time.sleep(interval)  # post_ids can follow PUBLISH_COMPLETE by up to three minutes
    raise TimeoutError(f"{share_id} was not public after {give_up_after} s")


video = tt.call("POST", "business/video/publish/", body={
    "video_url": "https://media.example.com/tiktok/launch.mp4",  # on a verified domain or URL prefix
    "post_info": {
        "caption": "Our spring menu is live #food",
        "is_brand_organic": True,  # the Promotional content label, for the account's own business
        "is_branded_content": False,
    },
})
print("Live:", wait_until_live(tt, video["share_id"]))

// Node.js
async function waitUntilLive(tt, shareId, everyMs = 30000, giveUpAfterMs = 7200000) {
  const deadline = Date.now() + giveUpAfterMs;
  while (Date.now() < deadline) {
    const s = await tt.call("GET", "business/publish/status/", { params: { publish_id: shareId } });
    if (s.status === "FAILED") throw new Error("TikTok did not publish " + shareId + ": " + s.reason);
    if (s.status === "PUBLISH_COMPLETE" && s.post_ids && s.post_ids.length) return s.post_ids;
    await sleep(everyMs); // post_ids can follow PUBLISH_COMPLETE by up to three minutes
  }
  throw new Error(shareId + " was not public after " + giveUpAfterMs / 1000 + " s");
}

async function publishVideo(tt) {
  const video = await tt.call("POST", "business/video/publish/", {
    body: {
      video_url: "https://media.example.com/tiktok/launch.mp4", // on a verified domain or URL prefix
      post_info: { caption: "Our spring menu is live #food", is_brand_organic: true, is_branded_content: false },
    },
  });
  return waitUntilLive(tt, video.share_id);
}

publishVideo(tt).then((postIds) => console.log("Live:", postIds), console.error);

फ़ोटो कैसे पोस्ट करें?

पहले खाते की अनुमत सेटिंग पढ़ें, फिर POST /business/photo/publish/ भेजें। फ़ोटो पोस्ट में privacy_level अनिवार्य है, और वह /business/video/settings/ की privacy_level_options में से एक होना चाहिए। अगर वहाँ comment_disabled true है, तो disable_comment भी true होना चाहिए। लौटाए गए share_id को वीडियो की तरह उसी प्रतीक्षा फ़ंक्शन से फ़ॉलो किया जाता है:

Publish a photo post: Python, then Node.js
# Python
def publish_photos(tt, image_urls, title, caption):
    settings = tt.call("GET", "business/video/settings/")
    if "PUBLIC_TO_EVERYONE" not in settings["privacy_level_options"]:
        raise RuntimeError(f"Private account, choose from {settings['privacy_level_options']}")
    photo = tt.call("POST", "business/photo/publish/", body={
        "photo_images": image_urls,  # 1 to 35 JPG, JPEG or WebP links on a verified domain or prefix
        "photo_cover_index": 0,
        "post_info": {
            "title": title,  # up to 90 UTF-16 code units
            "caption": caption,  # up to 4,000
            "privacy_level": "PUBLIC_TO_EVERYONE",
            "disable_comment": settings["comment_disabled"],  # True when the account takes no comments
            "is_brand_organic": True,
            "is_branded_content": False,
        },
    })
    return wait_until_live(tt, photo["share_id"])


print(publish_photos(tt, ["https://media.example.com/menu/1.jpg", "https://media.example.com/menu/2.jpg"],
                     "Spring menu", "Four new dishes, from Friday #food"))

// Node.js
async function publishPhotos(tt, imageUrls, title, caption) {
  const settings = await tt.call("GET", "business/video/settings/");
  if (!settings.privacy_level_options.includes("PUBLIC_TO_EVERYONE")) {
    throw new Error("Private account, choose from " + settings.privacy_level_options.join(", "));
  }
  const photo = await tt.call("POST", "business/photo/publish/", {
    body: {
      photo_images: imageUrls, // 1 to 35 JPG, JPEG or WebP links on a verified domain or prefix
      photo_cover_index: 0,
      post_info: {
        title, // up to 90 UTF-16 code units
        caption, // up to 4,000
        privacy_level: "PUBLIC_TO_EVERYONE",
        disable_comment: settings.comment_disabled, // true when the account takes no comments
        is_brand_organic: true,
        is_branded_content: false,
      },
    },
  });
  return waitUntilLive(tt, photo.share_id);
}

publishPhotos(tt, ["https://media.example.com/menu/1.jpg", "https://media.example.com/menu/2.jpg"],
  "Spring menu", "Four new dishes, from Friday #food").then(console.log, console.error);

खाते के वीडियो की सूची कैसे लें?

GET /business/video/list/ को चाहे गए fields के साथ भेजें, जिनमें item_id भी शामिल हो, और सबसे नए से शुरू करके एक पेज में 20 पोस्ट तक लें। लौटाए गए cursor को, जो UTC टाइमस्टैम्प है और मिलीसेकंड में होता है, तब तक पास करें जब तक has_more true हो, और छोटे पेज की उम्मीद रखें: TikTok के ट्रस्ट और सेफ़्टी नियम सूची खत्म होने से पहले max_count से कम परिणाम लौटा सकते हैं।

List recent videos across pages: Python, then Node.js
# Python
def recent_videos(tt, how_many=60):
    params = {"fields": ["item_id", "create_time", "caption", "share_url", "video_views", "likes", "comments"],
              "max_count": 20}
    videos = []
    while len(videos) < how_many:
        page = tt.call("GET", "business/video/list/", params=params)
        videos += page.get("videos", [])
        if not page.get("has_more"):
            break
        params["cursor"] = page["cursor"]  # posts published before this UTC time, in milliseconds
    return videos[:how_many]


for v in recent_videos(tt):
    print(v["item_id"], v.get("video_views"), (v.get("caption") or "")[:60])

// Node.js
async function recentVideos(tt, howMany = 60) {
  const params = {
    fields: ["item_id", "create_time", "caption", "share_url", "video_views", "likes", "comments"],
    max_count: 20,
  };
  const videos = [];
  while (videos.length < howMany) {
    const page = await tt.call("GET", "business/video/list/", { params });
    videos.push(...(page.videos ?? []));
    if (!page.has_more) break;
    params.cursor = page.cursor; // posts published before this UTC time, in milliseconds
  }
  return videos.slice(0, howMany);
}

recentVideos(tt).then((videos) => {
  for (const v of videos) console.log(v.item_id, v.video_views, (v.caption || "").slice(0, 60));
}, console.error);

कमेंट कैसे पढ़ें और उनका जवाब कैसे दें?

GET /business/comment/list/ पर पोस्ट का item_id video_id के रूप में डालने से एक पेज में 30 कमेंट तक मिलते हैं, और POST /business/comment/reply/create/ किसी एक कमेंट का सार्वजनिक रूप से 1,200 अक्षरों तक के टेक्स्ट के साथ जवाब देता है। उदाहरण ऐसे टॉप-लेवल सार्वजनिक कमेंट का जवाब देता है जिनका अभी कोई जवाब नहीं है, खाते के अपने कमेंट छोड़ देता है, और शब्द-रचना आपके लिखे फ़ंक्शन पर छोड़ता है, क्योंकि TikTok पास-पास भेजे गए मिलते-जुलते कमेंट को स्पैम मानकर छिपा सकता है:

Reply to new comments on a video: Python, then Node.js
# Python
def reply_to_new_comments(tt, video_id, write_reply):
    page = tt.call("GET", "business/comment/list/", params={
        "video_id": video_id,  # the post's item_id
        "status": "PUBLIC",
        "sort_field": "create_time",
        "sort_order": "desc",
        "max_count": 30,
    })
    for comment in page.get("comments", []):
        if comment.get("owner") or comment.get("replies") or comment.get("parent_comment_id"):
            continue  # the account's own comments, threads with replies, and replies
        text = write_reply(comment)
        if text:
            tt.call("POST", "business/comment/reply/create/", body={
                "video_id": video_id, "comment_id": comment["comment_id"], "text": text,  # up to 1,200 characters
            })


def reply_for(comment):
    if "price" in (comment.get("text") or "").lower():
        return f"Hi {comment.get('display_name') or 'there'}, the price list is pinned on our profile."
    return None  # leave the rest to a person


reply_to_new_comments(tt, "<ITEM_ID>", reply_for)

// Node.js
async function replyToNewComments(tt, videoId, writeReply) {
  const page = await tt.call("GET", "business/comment/list/", {
    params: { video_id: videoId, status: "PUBLIC", sort_field: "create_time", sort_order: "desc", max_count: 30 },
  });
  for (const comment of page.comments ?? []) {
    if (comment.owner || comment.replies || comment.parent_comment_id) continue; // own, already replied to, or a reply
    const text = writeReply(comment);
    if (text) {
      await tt.call("POST", "business/comment/reply/create/", {
        body: { video_id: videoId, comment_id: comment.comment_id, text }, // up to 1,200 characters
      });
    }
  }
}

function replyFor(comment) {
  if ((comment.text || "").toLowerCase().includes("price")) {
    return "Hi " + (comment.display_name || "there") + ", the price list is pinned on our profile.";
  }
  return null; // leave the rest to a person
}

replyToNewComments(tt, "<ITEM_ID>", replyFor).catch(console.error);

खाते की इनसाइट्स कैसे पढ़ें?

GET /business/get/ को fields में फ़ील्ड नाम के साथ और अधिकतम 60 दिन की UTC तारीख की सीमा के साथ भेजें। followers_count दो बार आता है: डेटा के ऊपर मौजूदा कुल संख्या, और metrics के अंदर हर दिन का कुल, जिसके साथ उस दिन का video_views, profile_views, likes, comments और shares होता है। उदाहरण कल पर खत्म होता है, क्योंकि रोज़ की गिनती 24 से 48 घंटे देर से आती है:

Daily account metrics for the last 7 days: Python, then Node.js
# Python
from datetime import datetime, timedelta, timezone


def daily_insights(tt, days=7):
    yesterday = datetime.now(timezone.utc).date() - timedelta(days=1)  # counts arrive 24 to 48 h late
    data = tt.call("GET", "business/get/", params={
        "fields": ["followers_count", "video_views", "profile_views", "likes", "comments", "shares"],
        "start_date": (yesterday - timedelta(days=days - 1)).isoformat(),  # UTC, up to 60 days back
        "end_date": yesterday.isoformat(),
    })
    print("Followers now:", data.get("followers_count"))
    for day in data.get("metrics", []):
        print(day["date"], day.get("followers_count"), day.get("video_views"), day.get("likes"))


daily_insights(tt)

// Node.js
async function dailyInsights(tt, days = 7) {
  const utcDay = (daysAgo) => new Date(Date.now() - daysAgo * 86400000).toISOString().slice(0, 10);
  const data = await tt.call("GET", "business/get/", {
    params: {
      fields: ["followers_count", "video_views", "profile_views", "likes", "comments", "shares"],
      start_date: utcDay(days), // UTC, up to 60 days back
      end_date: utcDay(1), // counts arrive 24 to 48 h late
    },
  });
  console.log("Followers now:", data.followers_count);
  for (const day of data.metrics ?? []) console.log(day.date, day.followers_count, day.video_views, day.likes);
}

dailyInsights(tt).catch(console.error);

वेबहुक सिग्नेचर कैसे सत्यापित करें?

t मान, एक बिंदु और रॉ बॉडी का HMAC-SHA256 फिर से निकालें, ऐप सीक्रेट से बनी कुंजी से, s के साथ स्थिर समय पर तुलना करें, और जाँचें कि t हाल का है। कुछ भी पार्स होने से पहले बॉडी को बाइट्स के रूप में पढ़ें, तुरंत 200 लौटाएँ, और जाँच विफल होने पर x-tt-logid लॉग करें। Python के लिए Flask, और Node.js के लिए built-in http मॉड्यूल:

Receive a signed TikTok webhook: Python with Flask, then Node.js
# Python
import hashlib
import hmac
import json
import os
import time
from queue import Queue

from flask import Flask, request

app = Flask(__name__)
events = Queue()


def signature_ok(raw, header, secret, max_age=300):
    fields = {}
    for part in (header or "").split(","):
        key, sep, value = part.strip().partition("=")
        if sep:
            fields[key] = value
    t, s = fields.get("t", ""), fields.get("s", "").lower()
    if not t.isdigit() or len(s) != 64:
        return False
    expected = hmac.new(secret.encode(), t.encode() + b"." + raw, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, s) and abs(time.time() - int(t)) <= max_age


@app.post("/tiktok/webhook")
def tiktok_webhook():
    raw = request.get_data()  # the bytes TikTok signed, before any JSON parsing
    if not signature_ok(raw, request.headers.get("Tiktok-Signature"), os.environ["TIKTOK_APP_SECRET"]):
        app.logger.warning("Bad signature, x-tt-logid %s", request.headers.get("X-Tt-Logid"))
        return "", 401
    events.put(json.loads(raw))  # its content field is itself a JSON string: work on it elsewhere
    return "", 200

// Node.js
const { createServer } = require("node:http");
const { createHmac, timingSafeEqual } = require("node:crypto");

function signatureOk(raw, header, secret, maxAgeSec = 300) {
  const fields = {};
  for (const part of String(header ?? "").split(",")) {
    const i = part.indexOf("=");
    if (i > 0) fields[part.slice(0, i).trim()] = part.slice(i + 1).trim();
  }
  if (!/^\d+$/.test(fields.t ?? "") || !/^[0-9a-f]{64}$/i.test(fields.s ?? "")) return false;
  const expected = createHmac("sha256", secret).update(fields.t + ".").update(raw).digest();
  const fresh = Math.abs(Date.now() / 1000 - Number(fields.t)) <= maxAgeSec;
  return timingSafeEqual(expected, Buffer.from(fields.s, "hex")) && fresh;
}

const inbox = [];
createServer((req, res) => {
  if (req.method !== "POST" || req.url !== "/tiktok/webhook") return res.writeHead(404).end();
  const chunks = [];
  req.on("data", (chunk) => chunks.push(chunk));
  req.on("end", () => {
    const raw = Buffer.concat(chunks); // the bytes TikTok signed
    if (!signatureOk(raw, req.headers["tiktok-signature"], process.env.TIKTOK_APP_SECRET)) {
      console.warn("Bad signature, x-tt-logid", req.headers["x-tt-logid"]);
      return res.writeHead(401).end();
    }
    res.writeHead(200).end(); // answer first: TikTok retries anything but a 200 for up to 72 hours
    inbox.push(JSON.parse(raw.toString("utf8")));
  });
}).listen(3000);

वही काम easyCoexistence के ज़रिए कैसे चलाएँ?

https://easycoexistence.com/api/mcp से जुड़े Claude, ChatGPT या किसी दूसरे MCP क्लाइंट से टूल कॉल के रूप में, हर एक में list_social_accounts से लिया account_id देकर। easyCoexistence आपके मीडिया लिंक अपने सत्यापित यूआरएल प्रीफ़िक्स के ज़रिए TikTok को भेजता है, हर पोस्ट को तब तक ट्रैक करता है जब तक TikTok उसे पूरा या विफल न करे, और टोकन नवीनीकृत करता है, जबकि ठुकराई गई कॉल TikTok का code और मैसेज के साथ लौटती है:

The six jobs as MCP tool calls
// Publish a video by URL, then see where it stands
publish_tiktok_post { "account_id": "<ACCOUNT_ID>", "video_url": "https://media.example.com/tiktok/launch.mp4", "caption": "Our spring menu is live #food" }
get_tiktok_publish_status { "account_id": "<ACCOUNT_ID>", "share_id": "<SHARE_ID>" }

// Post photos
publish_tiktok_post { "account_id": "<ACCOUNT_ID>", "image_urls": ["https://media.example.com/menu/1.jpg", "https://media.example.com/menu/2.jpg"], "title": "Spring menu", "caption": "Four new dishes, from Friday #food" }

// List videos
list_social_posts { "account_id": "<ACCOUNT_ID>", "limit": 20 }

// Read comments and reply in public
list_social_comments { "account_id": "<ACCOUNT_ID>", "post_id": "<ITEM_ID>" }
reply_to_comment { "account_id": "<ACCOUNT_ID>", "post_id": "<ITEM_ID>", "comment_id": "<COMMENT_ID>", "text": "The price list is pinned on our profile." }

// Account insights
get_social_insights { "account_id": "<ACCOUNT_ID>", "metrics": ["followers_count", "video_views", "likes"], "params": { "start_date": "2026-10-26", "end_date": "2026-11-01" } }

// Comment events, signed by easyCoexistence, at your endpoint
set_social_webhook_destination { "account_id": "<ACCOUNT_ID>", "url": "https://hooks.example.com/tiktok/" }

आपका अपना कोड easyCoexistence से जुड़े खाते का इस्तेमाल कैसे करता है?

हर काम के लिए Partner एपीआई से खाते की क्रेडेंशियल लाएँ और उन्हें उसी क्लाइंट को दें। ec_live_ key के साथ GET /channels/{id}?credentials=1 api_base, business_id और token_expires_at के साथ मौजूदा access_token लौटाता है, या चैनल को फिर से कनेक्ट करने की ज़रूरत हो तो नोट के साथ null टोकन। पढ़ने, जवाब देने और इनसाइट्स का काम आपके अपने कोड से चलता है, जबकि पोस्ट POST /channels/{id}/posts या publish_tiktok_post से जाते हैं, जो मीडिया को सत्यापित प्रीफ़िक्स से भेजते हैं:

A current token from the Partner API, into the same client: Python, then Node.js
# Python
def tiktok_for(channel_id):
    res = requests.get(f"https://easycoexistence.com/api/v1/channels/{channel_id}", params={"credentials": "1"},
                       headers={"Authorization": f"Bearer {os.environ['EC_API_KEY']}"}, timeout=30)
    res.raise_for_status()
    creds = res.json()["credentials"]
    if not creds.get("access_token"):
        raise RuntimeError(creds.get("note"))  # the channel needs reconnecting
    return TikTok(creds["access_token"], creds["business_id"])


print(recent_videos(tiktok_for("<CHANNEL_ID>"), 20))

// Node.js
async function tiktokFor(channelId) {
  const res = await fetch("https://easycoexistence.com/api/v1/channels/" + channelId + "?credentials=1", {
    headers: { Authorization: "Bearer " + process.env.EC_API_KEY },
  });
  if (!res.ok) throw new Error("HTTP " + res.status + " from easyCoexistence");
  const { credentials } = await res.json();
  if (!credentials.access_token) throw new Error(credentials.note); // the channel needs reconnecting
  return new TikTok(credentials.access_token, credentials.business_id);
}

tiktokFor("<CHANNEL_ID>").then((account) => recentVideos(account, 20)).then(console.log, console.error);

आम गड़बड़ियाँ

  • बिना code जाँचे डेटा पढ़ना। जवाब में HTTP 200, code 40002 और कोई डेटा नहीं हो सकता, इसलिए गायब फ़ील्ड अक्सर वह गड़बड़ी है जिसे कोड ने छोड़ दिया।
  • आखिरी स्लैश हटाना। TikTok के पाथ / पर खत्म होते हैं, और उसके रिटर्न कोड परिशिष्ट में /tt_user/oauth2/refresh_token, बिना स्लैश के, उस कॉल के रूप में है जो HTTP 404 page not found पर खत्म होती है।
  • Node.js में reply_list से जवाब के ID लेना। TikTok का रेफ़रेंस reply_list के comment_id और video_id को नंबर बताता है, जिन्हें JSON.parse राउंड कर सकता है; /business/comment/reply/list/ उन्हें string में लौटाता है।
  • फ़ील्ड को कॉमा वाली सूची के रूप में भेजना। कारोबारी एपीआई JSON टेक्स्ट चाहता है, fields=["item_id","caption"], जबकि developers.tiktok.com वाला डिस्प्ले एपीआई fields=open_id,union_id लेता है।
EasyCoexistence के साथ ऐसा करना

प्रति कनेक्शन प्रति माह US$ 9 से US$ 0.75 तक, जैसे-जैसे कनेक्शन बढ़ते हैं कीमत घटती है, और पहले 3 दिन मुफ़्त।

अक्सर पूछे जाने वाले सवाल

क्या TikTok के खाता एपीआई के लिए आधिकारिक Python या Node.js SDK है?

TikTok का कारोबारी एपीआई SDK Python, JavaScript और Java में आता है, लेकिन उसकी एंडपॉइंट सूची विज्ञापन, रिपोर्टिंग और कारोबार सेंटर को कवर करती है, जिसमें कोई /business/ या /tt_user/ एंडपॉइंट नहीं है।

TikTok की कॉल HTTP 200 के साथ बिना डेटा क्यों लौटती है?

TikTok गड़बड़ियों की रिपोर्ट HTTP 200 जवाब के code फ़ील्ड में करता है। code और मैसेज पढ़ें: 40002 पैरामीटर की गड़बड़ी है, 40001 अनुमति की कमी, और 40100 थ्रॉटल की गई कॉल।

इन उदाहरणों को कौन-से Python और Node.js संस्करण चाहिए?

requests के साथ Python 3.9 या बाद का, वेबहुक के लिए Flask, और Node.js 18 या बाद का, जिसका built-in fetch और node:crypto बाकी सब कवर करते हैं।

क्या मैं TikTok एपीआई को ब्राउज़र से कॉल कर सकता हूँ?

कॉल अपने सर्वर पर रखें। TikTok का टोकन टाइप Bearer है, जिसे जो भी रखे वह इस्तेमाल कर सकता है, और टोकन एंडपॉइंट को आपके ऐप का client_secret चाहिए।

पढ़ना जारी रखें

TikTok एपीआई गाइड 2026: आपके ऐप से पहली पोस्ट तक2026 में TikTok API का रास्ता, क्रम से: कौन सा एपीआई, ऐप रिव्यू, स्कोप, टोकन, पब्लिश, स्टेटस, कमेंट, वेबहुक, इनसाइट्स और लिमिट।TikTok एपीआई के 2026 के बदलाव: क्या काम करना बंद हुआ और क्या करें2026 में TikTok एपीआई के बदलाव, नए से पुराने क्रम में: टोकन की अवधि, is_business_account, कमेंट की सीमा, फ़ॉर्म और सैंडबॉक्स, हर एक का समाधान।TikTok API कनेक्शन क्यों काम करना बंद करता है, और उसे चालू कैसे रखेंTikTok API for Business कनेक्शन क्यों रुकता है: 24 घंटे का टोकन, एक साल का रीफ़्रेश टोकन, रद्द एक्सेस, खाते के बदलाव और दोबारा कनेक्ट करना।एपीआई के ज़रिए TikTok पर वीडियो कैसे पोस्ट करेंबिज़नेस एपीआई से TikTok पर वीडियो पोस्ट करें: पब्लिश एंडपॉइंट, उसकी JSON बॉडी, लौटने वाला share_id और स्टेटस कॉल, curl और Python में।TikTok वेबहुक सत्यापित करें: Tiktok-Signature हेडर और उसे जाँचने का तरीकाNode.js में TikTok API for Business वेबहुक जाँचें: Tiktok-Signature हेडर का HMAC-SHA256, जो t, बिंदु और रॉ बॉडी से बनता है, ऐप सीक्रेट से।TikTok API रेट लिमिट: प्रति खाता, ऐप और एंडपॉइंट के अनुसार अनुरोधTikTok API रेट लिमिट: प्रति खाता और एंडपॉइंट 40 कॉल प्रति मिनट, Accounts API पर ऐप के लिए 600 या 1,000 प्रति मिनट, और चार ऐप लेवल।

दो मिनट में अपना पहला चैनल कनेक्ट करें।

किसी प्लैटफ़ॉर्म की समीक्षा का इंतज़ार नहीं। WhatsApp, Instagram, TikTok या कोई और चैनल कनेक्ट करें, फिर अपने AI से पोस्ट करने, जवाब देने या रिपोर्ट बनाने को कहें और उसे काम करते देखें।

  • 3 दिन मुफ़्त
  • कभी भी रद्द करें
  • सिर्फ़ आधिकारिक एपीआई
  • 24/7 निगरानी

इस तारीख को सत्यापित