TikTok API: How to Post TikTok Videos Using a Social Media API

January 2024: Please see the updated TikTok API walk-through guide.

Update 2022: Ayrshare now offers direct publishing of TikTok videos, comments, and advanced analytics. This mean you no longer need to open the TikTok mobile app to manually enter the caption text and publish the video. Just sent the API request with the caption text and the TikTok video is published.


You are probably familiar with the official TikTok app to create and share videos. But, did you know you can also post videos using the TikTok API? 

Using a social media API opens worlds of possibilities to create your own app, platform, or service for your users, such as scheduling TikTok posts directly from your platform. 

Ayrshare recently introduced direct TikTok video sharing and enhanced user profile data and analytics. Continue reading to learn about how to use the TikTok API for your own platform.

TikTok’s Growth

If you haven’t heard, TikTok is big! TikTok has over 3.3B installs worldwide, 1B monthly active users, and in Q4 2021 had the most installs ever in a single quarter. Their growth seems unstoppable and continues to accelerate during the pandemic lockdowns.

TikTok also has a thriving ecosystem of apps that support video creation and downloads. Major new companies that build upon TikTok will emerge – as has happened for Facebook and Instagram. And how did developers create these Facebook and Instagram 3rd party apps? By using an API.

Social Media APIs

An API, or Application Programming Interface, gives you, or your developers, the power to create your own app or platform and leverage the capabilities of 3rd parties. You build the experience (GUI) that exactly meets your business needs and on the backend harness the power of external datasets or functionality. 

For example, the popular weather app Dark Skies, now owned by Apple, has a unique interface and capabilities such as letting you know it will rain in 15 minutes. Dark Skies and all other weather apps need to get this weather data from somewhere and I guarantee they don’t have their own network of weather satellites. In the U.S. most weather apps get their data from the National Weather Service via their API and build their own GUI front-end and unique capabilities.

Social media schedulers do the same thing by using the social media APIs available from social networks such as LinkedIn, Facebook, or Twitter.

Share Videos Using the TikTok API

TikTok recently introduced the ability to directly share videos via their API – called the Video Kit. Previously you could only share via an iOS or Android app, but now you can post directly to their endpoint. Side note, there is also a TikTok Business API if you want to manage ads.

The TikTok social media endpoint uses typical OAuth with tokens. OAuth allows users to authenticate and grant permissions to your app. These grant tokens expire after 24 hours, but can be refreshed with an additional API call. However, after a year the user need to re-authenticate and give permissions again.

TikTok requires you to request approval and go through a review process for API access, which can take a few days to a few weeks. Since their API endpoint is so new, there are several missing features, such deleting posts, and bugs that might prevent quick development.

Finally, there are a few other interesting aspects of the TikTok API documentation you might want to explore, such as the Login Kit for integrating TikTok OAuth or TikTok Webhooks to get notified of actions.

Update: TikTok continues to enhance their APIs with a V2. The V2 API simplifies calls, error messaging, and workflow. All of the below calls still function.

Alternative Integration

An alternative option to directly integrating with the TikTok API is to integrate with Ayrshare’s social media API which includes TikTok integration. You no longer need approval or worry about the details of TikTok’s evolving API.

For example, to post a new TikTok video use the following Javascript code with the /post endpoint. Be sure to replace API_KEY with your key from the dashboard:

const data = {
  "post": "Today is a great day I say!",
  "platforms": [
    "tiktok"
  ],
  "mediaUrls": [
    "https://img.ayrshare.com/012/tiktok.mp4"
  ]
};

const requestOptions = {
  method: 'POST',
  headers: {
    "Authorization": `Bearer ${API_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify(data)
};

fetch("https://app.ayrshare.com/api/post", requestOptions)
  .then(res => res.json())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

@lisanguyen

Trying spicy lovers instant ramen #SpicyRamen #InstantRamen

♬ Mii! – VooDoo

Or if you prefer to call the Ayrshare TikTok API in Python:

import requests

payload = {'post': 'Today is a great day!', 
        'platforms': ['tiktok'],
        'mediaUrls': ['https://img.ayrshare.com/012/tiktok.mp4']}
headers = {'Content-Type': 'application/json', 
        'Authorization': 'Bearer API_KEY'}

r = requests.post('https://app.ayrshare.com/api/post', 
    json=payload, 
    headers=headers)
    
print(r.json())

After posting, go to your TikTok app to complete the posting by selecting the video and following the instructions.

TikTok Analytics API

In addition to posting videos to TikTok, you also might want TikTok analytics about the user’s account or individual post, such as how many views, shares, or likes. These insights into user behavior, engagement, and reach can help build your social media strategy.

For example, to get the user level analytics across all their TikTok videos call the /analytics API endpoint. Here is the code in Javascript:

const data = { platforms: ["tiktok"] };

const requestOptions = {
  method: 'POST',
  headers: {
    "Authorization": `Bearer ${API_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify(data)
};

fetch("https://app.ayrshare.com/api/analytics/social", requestOptions)
  .then(res => res.json())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

And the Python TikTok API code:

import requests

payload = {'platforms': ['tiktok']}
headers = {'Content-Type': 'application/json', 
        'Authorization': 'Bearer API_KEY'}

r = requests.post('https://app.ayrshare.com/analytics/social', 
    json=payload, 
    headers=headers)
    
print(r.json())

The user level analytics data returned includes the average video duration and total like, comments, share, and views.

{
   "tiktok": {
        "analytics": {
            "commentCountTotal": 23,
            "durationAverage": 10.058823529411764,
            "likeCountTotal": 1,
            "shareCountTotal": 2,
            "url": "https://www.tiktok.com/@funsun",
            "username": "@funsun",
            "videoCountTotal": 26,
            "viewCountTotal": 16
        }
    }
}

If you want to get analytics on individual TikTok videos, call the /analytics post endpoint. The post level analytics data returned includes the share link of the video, description, and counts of likes, comments, shares, and views. This feature is unique to Ayrshare.

{
    "tiktok": {
        "id": "7034682002927550598",    // ID of the post at TikTok
        "postUrl": "https://www.tiktok.com/@borneild/video/7034682002927550598?utm_campaign=tt4d_open_api&utm_source=awawnhyictaos7o",
        "analytics": {
            "commentCount": 23,
            "createTime": 1660057702, // UTC Unix epoch (in seconds)
            "created": "2022-08-09T15:08:22Z",
            "duration": 6,
            "embedLink": "https://www.tiktok.com/embed/v2/7129893524253756713",
            "likeCount": 22,
            "mediaType": "video",
            "musicTitle": "♬ original sound - tiff",    // if available
            "musicUrl": "https://www.tiktok.com/music/original-sound-6689804660171082501?refer=embed", // if available
            "name": "Mackly",
            "postUrl": "https://www.tiktok.com/@tiktoktime/video/7129893524253756713?utm_campaign=tt4d_open_api&utm_source=awawnhyictaos7o7",
            "shareCount": 0,
            "shareUrl": "https://www.tiktok.com/@tiktoktime/video/7129893524253756713?utm_campaign=tt4d_open_api&utm_source=awawnhyictaos7o7", // Deprecated, user postUrl
            "tags": [    // Tags included in the description
                {
                    "tag": "#foryoupage",
                    "url": "https://www.tiktok.com/tag/foryoupage"
                },
                {
                    "tag": "#petsoftiktok",
                    "url": "https://www.tiktok.com/tag/petsoftiktok"
                },
                {
                    "tag": "#aesthetic",
                    "url": "https://www.tiktok.com/tag/aesthetic"
                }
            ],
            "thumbnailHeight": 576,
            "thumbnailUrl": "https://p16-sign.tiktokcdn-us.com/obj/tos-useast5-p-0068-tx",
            "thumbnailWidth": 1006,
            "title": "Scramble up ur name & I’ll try to guess it😍❤️ #foryoupage #petsoftiktok #aesthetic"",
            "url": "https://www.tiktok.com/@tiktoktime",
            "videoDescription": "Scramble up ur name & I’ll try to guess it😍❤️ #foryoupage #petsoftiktok #aesthetic"",
            "viewCount": 34
        }
    }
}

This insights data can be integrated into your app or platform for your users.

Start Sharing to TikTok

If you want to find out more about how to connect your TikTok account and post videos using our social API, check out our guide. Also, we have several integration packages to make things easier.

And of course, let us know if you have any questions.