Python మరియు Node.js లో TikTok API: పని చేసే ఉదాహరణలు
TikTok యొక్క API for Business, Python లేదా Node.js నుండి సాధారణ HTTPS అభ్యర్థనలతో పని చేస్తుంది: ప్రతి కాల్ను https://business-api.tiktok.com/open_api/v1.3 కు పంపండి, ఖాతా టోకెన్ను Access-Token హెడర్లో ఉంచండి, దాని open_id ను business_id గా ఇవ్వండి. TikTok చాలా కాల్స్కు HTTP 200 మరియు code ఫీల్డ్తో సమాధానం ఇస్తుంది, విజయవంతమైతే code 0; కాబట్టి దాన్ని తనిఖీ చేయండి, 40100 వస్తే 5 నిమిషాలు ఆగండి.
easyCoexistence, Claude, ChatGPT లేదా మీ స్వంత కోడ్కు అదే TikTok పనులను టూల్స్గా ఇస్తుంది: publish_tiktok_post, reply_to_comment నుండి get_social_insights వరకు, మరియు మీ స్క్రిప్ట్లకు get_social_credentials లేదా Partner API ద్వారా ప్రస్తుత టోకెన్ను ఇస్తుంది.
చాలా TikTok సమాధానాల HTTP స్టేటస్, లోపాలతో సహా; సమాధానంలో code 0 ఉంటేనే కాల్ పని చేసిందని అర్థం.
పరిమితి దాటిన కాల్కు కోడ్: నిమిషానికి పరిమితి దాటితే TikTok 5 నిమిషాల విరామం, రోజుకు పరిమితి దాటితే 00:00 UTC వరకు ఆగాలని కోరుతుంది.
సర్వర్ లోపాలు; ఆ తర్వాత TikTok సుమారు 5 నిమిషాలు ఆగి మళ్లీ కాల్ చేయమని సూచిస్తుంది.
మార్గాలు స్లాష్తో ముగుస్తాయి; స్లాష్ లేకుండా /tt_user/oauth2/refresh_token 404 page not found కు కారణమవుతుందని TikTok చెబుతుంది.
TikTok API for Business SDK లో Python, JavaScript, Java ఉన్నాయి, కానీ దాని ఎండ్పాయింట్ జాబితాలో /business/ ఎండ్పాయింట్ లేదు.
ప్రతి వెబ్హుక్ యొక్క Tiktok-Signature హెడర్లో సంతకం: టైమ్స్టాంప్, డాట్, బాడీ కలిపి, యాప్ సీక్రెట్తో కీ చేయబడింది.
ప్రతి TikTok API కాల్కు ఏమి కావాలి?
పని ఏదైనా సరే, ఈ ఐదు విషయాలు ఒకే విధంగా అవసరం:
- బేస్ URL 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 అయితే data ఇస్తుంది, లేకపోతే TikTokError రైజ్ చేస్తుంది. పరిమితి దాటిన కాల్ను TikTok 5 నిమిషాల విరామం తర్వాత మళ్లీ ప్రయత్నిస్తుంది, ఎందుకంటే 40100 అంటే TikTok కాల్ను తిరస్కరించింది; 5xx ను GET లో మాత్రమే మళ్లీ ప్రయత్నిస్తుంది, ఎందుకంటే సర్వర్ లోపంతో ముగిసిన పబ్లిష్ ఇంకా TikTok కు చేరి ఉండవచ్చు. దీనికి requests కావాలి, తర్వాతి Python ఉదాహరణలు దాన్నే వాడతాయి:
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 మరియు ఆ తర్వాతి వెర్షన్లలో ఉన్న బిల్ట్-ఇన్ fetch పై, ఏదీ ఇన్స్టాల్ చేయకుండా. GET కోసం లిస్ట్ పారామీటర్లను JSON గా ఎన్కోడ్ చేస్తుంది, POST లో business_id ను బాడీలో ఉంచుతుంది, ఎర్రర్పై TikTok code ను ఉంచుతుంది. దీంతో కాలర్లు 40102 లేదా 40105 (టోకెన్ సమస్య) ను 40001 (అనుమతి లేకపోవడం) నుండి వేరు చేయగలరు:
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 ద్వారా ఎలా పబ్లిష్ చేసి దాని స్టేటస్ ఎలా తనిఖీ చేయాలి?
video_url మరియు post_info తో POST /business/video/publish/ చేయండి, తర్వాత share_id ను publish_id గా పెట్టి /business/publish/status/ ను పోల్ చేయండి. FAILED వస్తే TikTok కారణంతో లూప్ ఆగుతుంది; PUBLISH_COMPLETE వస్తే post_ids వచ్చే వరకు వేచి ఉంటుంది, దానికి TikTok మరో మూడు నిమిషాల వరకు పట్టవచ్చని చెబుతుంది. video_url మీ యాప్ కోసం ధృవీకరించిన డొమైన్ లేదా URL ప్రిఫిక్స్పై ఉండాలి:
# 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 ను వీడియోలాగే అదే వేచి ఉండే ఫంక్షన్తో అనుసరించండి:
# 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 పోస్ట్లు వస్తాయి. has_more true ఉన్నంత వరకు, తిరిగి వచ్చిన cursor ను, అంటే మిల్లీసెకన్లలో UTC టైమ్స్టాంప్ ను, పంపండి. చిన్న పేజీలు రావచ్చని ఆశించండి: TikTok యొక్క ట్రస్ట్ అండ్ సేఫ్టీ నియమాల వల్ల జాబితా ముగియక ముందే max_count కంటే తక్కువ ఇవ్వవచ్చు.
# 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);కామెంట్లను ఎలా చదవాలి, వాటికి ఎలా సమాధానం ఇవ్వాలి?
పోస్ట్ యొక్క item_id ను video_id గా ఇచ్చి GET /business/comment/list/ ఒక్కో పేజీకి గరిష్టంగా 30 కామెంట్లు ఇస్తుంది. POST /business/comment/reply/create/ ఒక కామెంట్కు బహిరంగంగా 1,200 అక్షరాల వరకు టెక్స్ట్తో సమాధానం ఇస్తుంది. ఉదాహరణ, ఇంకా సమాధానాలు లేని టాప్ లెవెల్ బహిరంగ కామెంట్లకు మాత్రమే సమాధానం ఇస్తుంది, ఖాతా స్వంత కామెంట్లను దాటేస్తుంది. సమాధానం పదాలను మీరు రాసే ఫంక్షన్కే వదిలేస్తుంది, ఎందుకంటే దగ్గర సమయంలో దాదాపు ఒకేలా ఉన్న కామెంట్లను TikTok స్పామ్గా దాచవచ్చు:
# 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);ఖాతా ఇన్సైట్స్ను ఎలా చదవాలి?
fields లో ఫీల్డ్ పేర్లు ఇచ్చి GET /business/get/, గరిష్టంగా 60 రోజుల UTC తేదీ పరిధితో. followers_count రెండు సార్లు వస్తుంది: data పై భాగంలో ప్రస్తుత మొత్తం, metrics లోపల ప్రతి రోజు మొత్తం, ఆ రోజు video_views, profile_views, likes, comments మరియు shares తో పాటు. ఉదాహరణ నిన్నటితో ముగుస్తుంది, ఎందుకంటే రోజువారీ లెక్కలు 24 నుండి 48 గంటలు ఆలస్యంగా వస్తాయి:
# 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 విలువ, డాట్, raw body కలిపి HMAC-SHA256 ను మళ్లీ లెక్కించండి, యాప్ సీక్రెట్తో కీ చేయండి, s తో స్థిర సమయంలో పోల్చండి, మరియు t ఇటీవలిదని తనిఖీ చేయండి. ఏదైనా పార్స్ చేయడానికి ముందే body ను బైట్స్గా చదవండి, వెంటనే 200 ఇవ్వండి, తనిఖీ విఫలమైనప్పుడు x-tt-logid ను లాగ్ చేయండి. Python కు Flask, Node.js కు అంతర్నిర్మిత http మాడ్యూల్:
# 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 ద్వారా ఎలా చేయాలి?
Claude, ChatGPT లేదా మరో MCP క్లయింట్, https://easycoexistence.com/api/mcp కు కనెక్ట్ అయి, టూల్ కాల్స్గా ఇవ్వండి; ప్రతి కాల్లో list_social_accounts నుండి account_id ఇవ్వండి. easyCoexistence మీ మీడియా లింక్లను TikTok కు దాని స్వంత ధృవీకరించిన URL ప్రిఫిక్స్ ద్వారా పంపుతుంది, ప్రతి పోస్ట్ను TikTok పూర్తి చేసే లేదా విఫలం చేసే వరకు అనుసరిస్తుంది, టోకెన్ను రీన్యూ చేస్తుంది; తిరస్కరించిన కాల్ TikTok code మరియు message తో తిరిగి వస్తుంది:
// 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 API నుండి తీసుకుని అదే క్లయింట్కు ఇవ్వండి. మీ ec_live_ కీతో GET /channels/{id}?credentials=1 api_base, business_id మరియు token_expires_at తో కూడిన ప్రస్తుత access_token ఇస్తుంది, లేదా ఛానల్ను మళ్లీ కనెక్ట్ చేయాల్సి వస్తే, వివరణతో null టోకెన్ ఇస్తుంది. చదవడం, సమాధానాలు, ఇన్సైట్స్ మీ కోడ్ నుండే నడుస్తాయి; పోస్ట్లు POST /channels/{id}/posts లేదా publish_tiktok_post ద్వారా వెళ్తాయి, అవి మీడియాను ధృవీకరించిన ప్రిఫిక్స్ ద్వారా పంపుతాయి:
# 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 ఉండి అసలు data ఉండకపోవచ్చు, కాబట్టి ఫీల్డ్ లేకపోవడం తరచుగా మీ కోడ్ దాటేసిన లోపమే.
- చివరి స్లాష్ తీసేయడం. TikTok మార్గాలు / తో ముగుస్తాయి, మరియు దాని రిటర్న్ కోడ్ అనుబంధంలో /tt_user/oauth2/refresh_token ను స్లాష్ లేకుండా ఇవ్వడం HTTP 404 page not found తో ముగిసే కాల్గా చూపుతుంది.
- Node.js లో reply_list నుండి reply ఐడీలు తీసుకోవడం. TikTok రిఫరెన్స్ reply_list యొక్క comment_id మరియు video_id ను సంఖ్యలుగా టైప్ చేస్తుంది, వీటిని JSON.parse రౌండ్ చేయగలదు; /business/comment/reply/list/ వాటిని స్ట్రింగ్లుగా ఇస్తుంది.
- fields ను కామా జాబితాగా పంపడం. API for Business కు JSON టెక్స్ట్ కావాలి, fields=["item_id","caption"], developers.tiktok.com లోని Display API కు భిన్నంగా, అది fields=open_id,union_id తీసుకుంటుంది.
ఒక్కో కనెక్షన్కు నెలకు US$ 9 నుండి US$ 0.75 వరకు, మీరు కనెక్షన్లు జోడించిన కొద్దీ తగ్గుతూ, మొదటి 3 రోజులు ఉచితం.
తరచుగా అడిగే ప్రశ్నలు
TikTok Accounts API కోసం అధికారిక Python లేదా Node.js SDK ఉందా?
TikTok API for Business SDK Python, JavaScript మరియు Java లలో వస్తుంది, కానీ దాని ఎండ్పాయింట్ జాబితా యాడ్స్, రిపోర్టింగ్ మరియు Business Center ను కవర్ చేస్తుంది, /business/ లేదా /tt_user/ ఎండ్పాయింట్ ఏదీ లేకుండా.
TikTok కాల్ HTTP 200 తో డేటా లేకుండా ఎందుకు తిరిగి వస్తుంది?
TikTok లోపాలను HTTP 200 సమాధానంలోని code ఫీల్డ్లో చూపుతుంది. code మరియు message చదవండి: 40002 అంటే పారామీటర్ లోపం, 40001 అనుమతి లేకపోవడం, 40100 పరిమితి దాటిన కాల్.
ఈ ఉదాహరణలకు ఏ Python మరియు Node.js వెర్షన్లు కావాలి?
requests తో Python 3.9 లేదా ఆ తర్వాతిది, వెబ్హుక్ కోసం Flask తో, మరియు Node.js 18 లేదా ఆ తర్వాతిది; దాని అంతర్నిర్మిత fetch మరియు node:crypto మిగతావన్నీ కవర్ చేస్తాయి.
బ్రౌజర్ నుండి TikTok API కు కాల్ చేయవచ్చా?
కాల్స్ను మీ సర్వర్లోనే ఉంచండి. TikTok టోకెన్ రకం Bearer, దాన్ని కలిగి ఉన్న ఎవరైనా వాడగలరు, మరియు టోకెన్ ఎండ్పాయింట్లకు మీ యాప్ యొక్క client_secret అవసరం.
చదవడం కొనసాగించండి
మీ మొదటి ఛానెల్ను రెండు నిమిషాల్లో కనెక్ట్ చేయండి.
ప్లాట్ఫామ్ సమీక్షల కోసం ఎదురుచూడాల్సిన అవసరం లేదు. WhatsApp, Instagram, TikTok లేదా మరో ఛానెల్ను కనెక్ట్ చేయండి, ఆపై పోస్ట్ చేయమని, ప్రత్యుత్తరం ఇవ్వమని లేదా రిపోర్ట్ ఇవ్వమని మీ AIకి చెప్పండి, అది పని చేయడం చూడండి.
- 3 రోజులు ఉచితం
- ఎప్పుడైనా రద్దు చేయండి
- అధికారిక APIలు మాత్రమే
- 24/7 పర్యవేక్షణ
ధృవీకరించిన తేదీ