Skip to content

Python Integration ​

Automate video publishing and scrape creator posts with Python using requests.


1. Installation ​

bash
pip install requests

2. Publish Script (publish_video.py) ​

python
import os
import requests

API_BASE_URL = "https://api.stackvid.dev/api"
API_KEY = os.getenv("STACKVID_API_KEY", "tk_live_YOUR_KEY")

headers = {
    "X-API-Key": API_KEY,
    "Content-Type": "application/json"
}

def upload_and_publish(video_path: str, caption: str, channel_name: str = None):
    file_size = os.path.getsize(video_path)

    # 1. Request Presigned URL
    r = requests.post(f"{API_BASE_URL}/uploads/presigned-url", json={
        "fileType": "VIDEO",
        "contentType": "video/mp4",
        "fileSizeBytes": file_size
    }, headers=headers)
    r.raise_for_status()
    presigned = r.json()

    # 2. Binary PUT to uploadUrl
    with open(video_path, "rb") as f:
        requests.put(presigned["uploadUrl"], data=f, headers={"Content-Type": "video/mp4"}).raise_for_status()

    # 3. Publish to TikTok
    pub_res = requests.post(f"{API_BASE_URL}/tiktok/upload", json={
        "videoUrl": presigned["publicUrl"],
        "caption": caption,
        "targetChannel": channel_name,
        "privacyLevel": 0
    }, headers=headers)
    pub_res.raise_for_status()
    return pub_res.json()

if __name__ == "__main__":
    result = upload_and_publish("promo.mp4", "New launch video! #trending")
    print("Published successfully:", result.get("shareUrl"))

3. Scrape Creator Posts (crawl_posts.py) ​

python
import requests

def scrape_creator(username: str, count: int = 35):
    res = requests.get(
        f"{API_BASE_URL}/tiktok/user/posts",
        headers=headers,
        params={"username": username, "count": count}
    )
    res.raise_for_status()
    data = res.json()
    for item in data.get("itemList", []):
        stats = item.get("stats", {})
        video = item.get("video", {})
        print(f"ID: {item['id']} | Views: {stats.get('playCount'):,} | No-Watermark: {video.get('playAddr')}")

if __name__ == "__main__":
    scrape_creator("lamine.yamal")

StackVid - Multi-Platform Video & Social Commerce Automation Platform.