### Start Live Video using TikAPI - Request Samples Source: https://tikapi.io/documentation/index These code snippets demonstrate how to initiate a live video stream using the TikAPI. They include examples for payload structure, Javascript, Python, and CURL, allowing developers to integrate live streaming functionality into their applications. Authorization with API Key and Account Key is required. ```json { "title": "Check out my live!", "third_party": true, "hashtag_id": 0, "game_tag_id": 0 } ``` ```javascript const tikapi = require('tikapi'); const client = new tikapi.TikTokApiClient({ cookie: process.env.TIKTOK_COOKIE || '', // or use your own session // session: your_session }); async function main() { const user_id = client.account('user_id'); // You can get this value from the client.login(username, password) response const live = await client.live.start({ // You can find the hashtag id by using the client.hashtag.list() title: 'Check out my live!', // required // hashtag_id: 0, // optional // game_tag_id: 0, // optional // third_party: true, // optional }); console.log(live); } main(); ``` ```python from TikTokApi import TikTokApi tikapi = TikTokApi() async def main(): user_id = tikapi.user_id # You can get this value from the tikapi.login(username, password) response live = await tikapi.live.start( # You can find the hashtag id by using the tikapi.hashtag.list() title='Check out my live!', # required # hashtag_id=0, # optional # game_tag_id=0, # optional # third_party=True, # optional ) print(live) tikapi.run_until_complete(main()) ``` ```curl curl --request POST \ --url https://api.tikapi.io/user/live/start \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --header 'x-key: YOUR_API_KEY' \ --header 'x-user: YOUR_ACCOUNT_KEY' \ --data '{ "title": "Check out my live!", "third_party": true, "hashtag_id": 0, "game_tag_id": 0 }' ``` -------------------------------- ### Install TikAPI for Javascript (npm) Source: https://tikapi.io/documentation/index This command installs the latest version of the TikAPI library for Javascript projects using npm. Ensure you have Node.js and npm installed on your system. ```bash npm i tikapi@latest ``` -------------------------------- ### Get Music Posts using Python Source: https://tikapi.io/documentation/index Provides a Python example for fetching posts linked to a given music ID via the TikAPI. This snippet illustrates how to initialize the API client, specify the music ID and optional parameters like count and country, and make the request. Pagination is managed by the library. ```python from tikapi import TikAPI api = TikAPI("myAPIKey") async def get_music_posts(): try: # Example: Get posts for a music ID response = await api.public.music( id="28459463", # Music ID or short TikTok link count=30, # Optional: Max items per request (default 30) country="us" # Optional: Proxy country ISO Code ) print(response.json) # The library handles pagination, but you can manually paginate if needed: # while response: # cursor = response.json.get('cursor') # response = await response.next_items() except Exception as e: print(e) # To run the async function: # import asyncio # asyncio.run(get_music_posts()) ``` -------------------------------- ### Install TikAPI for Python (pip) Source: https://tikapi.io/documentation/index This command installs or upgrades the TikAPI library for Python projects using pip. It's recommended to use pip3 for modern Python installations. ```bash pip3 install tikapi --upgrade ``` -------------------------------- ### Get TikTok User Feed Posts Source: https://tikapi.io/documentation/index This code example shows how to fetch a user's feed posts using the TikAPI. It requires the user's secUid and supports pagination through the cursor parameter. The function also includes logic for iterating through multiple pages of posts. ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); (async function(){ try{ let response = await api.public.posts({ secUid: "MS4wLjABAAAAsHntXC3s0AvxcecggxsoVa4eAiT8OVafVZ4OQXxy-9htpnUi0sOYSr0kGGD1Loud" }); console.log(response?.json); while(response){ let cursor = response?.json?.cursor; console.log("Getting next items ", cursor); response = await Promise.resolve( response?.nextItems() ); } } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` -------------------------------- ### Get Public Playlist Items with Pagination (Javascript) Source: https://tikapi.io/documentation/index This Javascript code snippet demonstrates how to fetch items from a public playlist using the TikAPI. It includes an example of handling pagination by utilizing the cursor returned in the response. Ensure you have the 'tikapi' library installed and a valid API key. ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); (async function(){ try{ let response = await api.public.playlistItems({ playlist_id: "6948562344666532614" }); console.log(response?.json); while(response){ let cursor = response?.json?.cursor; console.log("Getting next items ", cursor); response = await Promise.resolve( response?.nextItems() ); } } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` -------------------------------- ### Get Comment Replies using CURL Source: https://tikapi.io/documentation/index Shows how to retrieve TikTok comment replies using a CURL command. This example requires specifying the media ID and comment ID in the request body. Authentication is done via the API key in the headers. ```curl curl -X POST "https://api.tikapi.io/public/commentRepliesList" \ -H "Authorization: Bearer myAPIKey" \ -H "Content-Type: application/json" \ -d '{ "media_id": "7109178205151464746", "comment_id": "7109185042560680750" }' ``` -------------------------------- ### Sandbox Configuration Source: https://tikapi.io/documentation/index Instructions for enabling the sandbox environment in Javascript and Python, along with sandbox API and account keys. ```APIDOC ## Sandbox Configuration ### Enabling Sandbox in Javascript ```javascript api.set({ $sandbox: true }); ``` ### Enabling Sandbox in Python ```python api.set( __sandbox__=True ) ``` ### Sandbox API Key `DemoAPIKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39Asd4s` ### Sandbox Account Key `DemoAccountKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39A` ``` -------------------------------- ### Sandbox API and Account Keys Source: https://tikapi.io/documentation/index These are example keys provided for testing the Tikapi sandbox environment. They are used to authenticate requests during development and testing phases. ```text DemoAPIKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39Asd4s ``` ```text DemoAccountKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39A ``` -------------------------------- ### Get Music Posts using Javascript Source: https://tikapi.io/documentation/index Demonstrates how to retrieve posts associated with a specific music ID using the TikAPI Javascript SDK. This example shows how to specify the music ID, and optionally the country for the proxy. The SDK handles pagination internally. ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); (async function(){ try{ // Example: Get posts for a music ID let response = await api.public.music({ id: "28459463", // Music ID or short TikTok link count: 30, // Optional: Max items per request (default 30) country: "us" // Optional: Proxy country ISO Code }); console.log(response?.json); // The library handles pagination, but you can manually paginate if needed: // while(response){ // let cursor = response?.json?.cursor; // response = await response?.nextItems(); // } } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` -------------------------------- ### Discover Content (Users, Music, Hashtags) with Pagination Source: https://tikapi.io/documentation/index This example demonstrates how to discover popular content like users, music, or hashtags using the TikAPI. It supports pagination, allowing you to fetch items in batches by utilizing the `nextItems()` method. The `category` parameter is required, and optional query parameters like `count`, `offset`, and `country` can be used. Error handling is included. ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); (async function(){ try{ let response = await api.public.discover({ category: "users" }); console.log(response?.json); while(response){ let offset = response?.json?.offset; console.log("Getting next items ", offset); response = await Promise.resolve( response?.nextItems() ); } } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` -------------------------------- ### Get User Following List - Javascript Source: https://tikapi.io/documentation/index This Javascript code snippet demonstrates how to use the TikAPI library to fetch a user's following list. It handles pagination by continuously fetching the next set of items until none are available. The example includes error handling for API requests. ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); (async function(){ try{ let response = await api.public.followingList({ secUid: "MS4wLjABAAAAsHntXC3s0AvxcecggxsoVa4eAiT8OVafVZ4OQXxy-9htpnUi0sOYSr0kGGD1Loud" }); console.log(response?.json); while(response){ let nextCursor = response?.json?.nextCursor; console.log("Getting next items ", nextCursor); response = await Promise.resolve( response?.nextItems() ); } } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` -------------------------------- ### Get User Playlists - JavaScript Source: https://tikapi.io/documentation/index This JavaScript code snippet demonstrates how to fetch a user's playlists using the TikAPI library. It initializes the API with a key, sets up the user object with an account key, and then calls the `playlists()` method to retrieve playlist data. The code includes a loop to fetch subsequent pages of results using the cursor, along with error handling. ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); const User = new api.user({ accountKey: "DemoAccountKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39A" }); (async function(){ try{ let response = await User.posts.playlists(); console.log(response?.json); while(response){ let cursor = response?.json?.cursor; console.log("Getting next items ", cursor); response = await Promise.resolve( response?.nextItems() ); } } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` -------------------------------- ### Get Live Videos List - Javascript Source: https://tikapi.io/documentation/index This Javascript code snippet demonstrates how to use the TikAPI library to fetch a list of live videos. It initializes the API with an API key and account key, then calls the `live.list()` method. Error handling is included for API responses. ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); const User = new api.user({ accountKey: "DemoAccountKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39A" }); (async function(){ try{ let response = await User.live.list(); console.log(response.json); } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` -------------------------------- ### GET /user/live/recommend Source: https://tikapi.io/documentation/index Retrieves a list of recommended live videos related to a specific live video room. ```APIDOC ## GET /user/live/recommend ### Description Get a list of recommended live videos, related with a live video. ### Method GET ### Endpoint https://api.tikapi.io/user/live/recommend (Sandbox: https://sandbox.tikapi.io/user/live/recommend) ### Parameters #### Query Parameters - **room_id** (string) - Required - The Live room ID. You can find this using the Get profile information endpoint. Example: room_id=7112492061034646278 ### Request Example ```javascript // Javascript Example import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); const User = new api.user({ accountKey: "DemoAccountKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39A" }); (async function(){ try{ let response = await User.live.recommend({ room_id: "7112492061034646278" }); console.log(response.json); } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` ### Response #### Success Response (200) - **status** (string) - Indicates the status of the operation (e.g., "success"). - **status_code** (integer) - The status code of the operation (0 for success). - **message** (string) - An empty string if the operation was successful. - **extra** (object) - Contains additional information, including a timestamp ('now'). #### Response Example ```json { "with_draw_something": false, "with_ktv": false, "with_linkmic": true } ``` #### Error Response (403) - **message** (string) - A description of the error. - **status_code** (integer) - The error status code. - **extra** (object) - Contains additional information, including a timestamp ('now'). ``` -------------------------------- ### GET /user/feed Source: https://tikapi.io/documentation/index Retrieves the current user's feed posts. You can also specify a `secUid` to get posts from another user. ```APIDOC ## GET /user/feed ### Description Get current user feed posts, or someone elses by providing the `secUid` parameter. ### Method GET ### Endpoint https://api.tikapi.io/user/feed ### Parameters #### Query Parameters - **count** (number) - Optional - Maximum amount of items for one request. Default: 30. Max: 30. - **cursor** (string) - Optional - The starting point of the items list. Returned in every response, should be included in the next request for iteration. (A simple iteration method is already implemented in the Javascript & Python libraries as seen in the request samples) - **secUid** (string) - Optional - The TikTok user secUid. You can get this from the Get profile information endpoint using the username. ### Request Example ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); const User = new api.user({ accountKey: "DemoAccountKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39A" }); (async function(){ try{ let response = await User.posts.feed(); console.log(response?.json); while(response){ let cursor = response?.json?.cursor; console.log("Getting next items ", cursor); response = await Promise.resolve( response?.nextItems() ); } } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` ### Response #### Success Response (200) - **message** (string) - An empty string. - **status** (string) - "success" #### Response Example ```json { "message": "", "status": "success" } ``` ``` -------------------------------- ### POST /user/live/start Source: https://tikapi.io/documentation/index Initiates a live video stream for a user who has live streaming enabled. The stream is automatically closed once it ends. ```APIDOC ## POST /user/live/start ### Description Starts a live video stream. This endpoint is available for users with live streaming capabilities. The live stream will be automatically terminated once the stream concludes. ### Method POST ### Endpoint `https://api.tikapi.io/user/live/start` (Live Server) `https://sandbox.tikapi.io/user/live/start` (Sandbox Server) ### Parameters #### Request Body - **title** (string) - Required - The title for the live room header. - **third_party** (boolean) - Optional, Default: `true` - Enables third-party streaming if TikTok's special gateway for invite-only users is active. - **hashtag_id** (number) - Optional - The ID of the topic. This can be obtained using the 'Get topics list' endpoint. - **game_tag_id** (number) - Optional - The sub-topic ID for gaming-related topics. ### Request Example ```json { "title": "Check out my live!", "third_party": true, "hashtag_id": 0, "game_tag_id": 0 } ``` ### Response #### Success Response (200) - **data** (object) - Contains detailed information about the live stream setup. - **access_recall_info** (array) - Information about access recall. - **age_restricted_config** (object) - Configuration for age restrictions. - **anchor_fans_info** (object) - Information about the anchor's fans. - **anchor_prompt_type** (number) - Anchor prompt type. - **ban_status** (object) - Ban status information. - **banner_data** (object) - Banner data for the live stream. - **block_detail_url** (string) - URL for block details. - **block_prompt** (string) - Prompt message for blocking. - **block_schema_locale** (string) - Locale for block schema. - **block_status** (number) - Block status code. - **can_show_fragment** (boolean) - Whether fragments can be shown. - **cover** (object) - Cover image details. - **cover_audit_status** (number) - Cover audit status. - **deprecate1** (number) - Deprecated field. - **deprecate3** (number) - Deprecated field. - **deprecate4** (string) - Deprecated field. - **device_level** (number) - Device level. - **donation_sticker** (number) - Donation sticker status. - **game_guide_info** (array) - Information about game guides. - **game_live_convert_info** (object) - Information about game live conversion. - **game_live_info** (object) - Information about game live status. - **go_live_prompt** (string) - Prompt message for going live. - **guide_status** (number) - Guide status. - **has_fragment** (boolean) - Whether fragments are present. - **is_new_anchor** (boolean) - Whether the anchor is new. - **last_room_id** (number) - ID of the last room. - **last_room_id_str** (string) - String representation of the last room ID. - **live_additional_prompt** (string) - Additional prompt for live streams. - **live_house_status** (number) - Live house status. - **live_scenario** (object) - Live scenario configurations. - **live_status** (number) - Current live status. - **never_go_live_flag** (number) - Flag indicating if never going live. - **obs_accees_recall_info** (object) - OBS access recall information. - **pop_info** (object) - Pop-up information. - **push_stream_info** (object) - Push stream information, including quality settings. - **screenshot_cover_status** (number) - Screenshot cover status. - **show_game_tags** (boolean) - Whether to show game tags. - **stream_status** (number) - Stream status. - **title** (string) - The title of the live stream. - **use_avatar_as_cover** (boolean) - Whether to use avatar as cover. - **extra** (object) - Additional information, such as the current timestamp. - **message** (string) - Status message. - **status** (string) - Overall status ('success'). - **status_code** (number) - Status code (0 for success). #### Response Example ```json { "data": { "access_recall_info": [], "age_restricted_config": { "disabled": false, "disabled_reason": "", "open": false, "show": true }, "anchor_fans_info": { "avatar_pick_reason": [], "avatar_type": 0, "avatars": [], "living_friend_count": 0, "no_online_fans_count_reason": 2, "online_fans_count": 0, "online_friend_count": 0 }, "anchor_prompt_type": 0, "ban_status": { "end_time": 0, "is_ban": false }, "banner_data": { "banner_list": [], "container_height": 0, "container_type": 0, "container_url": "https://ttlive.tiktok.com/falcon/webcast_mt/page/activity_multi_banner/index.html", "container_width": 0, "lynx_container_url": "" }, "block_detail_url": "", "block_prompt": "", "block_schema_locale": "", "block_status": 0, "can_show_fragment": true, "cover": { "avg_color": "", "height": 0, "image_type": 0, "is_animated": false, "open_web_url": "", "uri": "tos-maliva-avt-0068/9f25676d45ce0451d722997ef71f7804", "url_list": [ "https://p16-webcast.tiktokcdn.com/img/maliva/tos-maliva-avt-0068/9f25676d45ce0451d722997ef71f7804~tplv-obj.image" ], "width": 0 }, "cover_audit_status": 2, "deprecate1": 0, "deprecate3": 0, "deprecate4": "", "device_level": 0, "donation_sticker": 1, "game_guide_info": [ { "create_scene": 1, "show_game_live_guide": true } ], "game_live_convert_info": { "acu_type": 0, "convert_type": 0, "text": "", "title": "" }, "game_live_info": { "has_comment_in_game_live": false, "has_game_live": false, "has_game_live_2min": false }, "go_live_prompt": "", "guide_status": 0, "has_fragment": false, "is_new_anchor": false, "last_room_id": 7113508115123211000, "last_room_id_str": "7113508115123211017", "live_additional_prompt": "Make sure LIVE isn't interrupted. Switching to other apps during LIVE may pause the broadcast and reset the stream key.", "live_house_status": 0, "live_scenario": { "enable_live_audio": false, "enable_live_screenshot": false, "enable_live_studio": false, "enable_live_third_party": false }, "live_status": 4, "never_go_live_flag": 0, "obs_accees_recall_info": { "duration": 0, "end_timestamp": 0, "status": 0 }, "pop_info": { "button_content": [], "content": "", "has_pop": false }, "push_stream_info": { "1": { "default_quality": { "desc": "", "name": "540p", "sdk_key": "sd" }, "qualities": [ { "desc": "", "name": "540p", "sdk_key": "sd" } ] }, "4": { "default_quality": { "desc": "", "name": "540p", "sdk_key": "sd" }, "qualities": [ { "desc": "", "name": "540p", "sdk_key": "sd" } ] } }, "screenshot_cover_status": 1, "show_game_tags": true, "stream_status": 0, "title": "Powered by TikAPI", "use_avatar_as_cover": true }, "extra": { "now": 1656248396102 }, "message": "", "status": "success", "status_code": 0 } ``` #### Error Response (403) - **message** (string) - Description of the error. - **status** (string) - Status of the error (e.g., 'error'). - **status_code** (number) - Error code. ``` -------------------------------- ### GET /user/followers Source: https://tikapi.io/documentation/index Retrieves the current user's followers list. You can also specify a `secUid` to get a specific user's followers. ```APIDOC ## GET /user/followers ### Description Get current user followers list (or a friends by specifying the secUid). ### Method GET ### Endpoint https://api.tikapi.io/user/followers ### Parameters #### Query Parameters - **secUid** (string) - Optional - The TikTok user secUid. You can get this from the Get profile information endpoint using the username. - **count** (number) - Optional - Maximum amount of items for one request. Default: 30. Max: 30. - **nextCursor** (number) - Optional - A iteration parameter returned in each response, should be included in the next requests to get the next items. ### Request Example ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); const User = new api.user({ accountKey: "DemoAccountKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39A" }); (async function(){ try{ let response = await User.followers(); console.log(response?.json); while(response){ let nextCursor = response?.json?.nextCursor; console.log("Getting next items ", nextCursor); response = await Promise.resolve( response?.nextItems() ); } } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ``` ### Response #### Success Response (200) - **message** (string) - An empty string. - **status** (string) - "success" #### Response Example ```json { "message": "", "status": "success" } ``` ``` -------------------------------- ### Initialize TikAPI in Javascript (ES6 Module) Source: https://tikapi.io/documentation/index Initializes the TikAPI client in Javascript using ES6 import syntax. Requires an API Key for authentication. This setup is intended for server-side usage. ```javascript import TikAPI from 'tikapi'; const api = TikAPI('DemoAPIKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39Asd4s'); ``` -------------------------------- ### GET /public/music/info Source: https://tikapi.io/documentation/index Retrieves information about a specific music track on TikTok. This endpoint allows you to get details by providing a music ID or a TikTok short link. ```APIDOC ## GET /public/music/info ### Description Retrieves information about a specific music track on TikTok. This endpoint allows you to get details by providing a music ID or a TikTok short link. ### Method GET ### Endpoint https://api.tikapi.io/public/music/info ### Query Parameters - **id** (string) - Required - The music ID. Can also be a short TikTok link (e.g. vm.tiktok.com/UwU). - **country** (string) - Optional - You can optionally choose the proxy country from where the request is being sent by providing an ISO Code (e.g us, ca, gb) — 200+ countries supported. ### Responses #### Success Response (200) - **(object)** - Music information. #### Error Response (403) - **(object)** - Indicates an error occurred. ### Request Example ``` GET /public/music/info?id=28459463&country=us ``` ### Response Example (200) ```json { "data": { "UrlList": [ "https://v16-webapp-prime.us.tiktok.com/video/tos/useast5/tos-useast5-pve-0068-tx/25fcb4fec3ae4bed9629904e56d67104/?a=1988&ch=0&cr=3&dr=0&lr=unwatermarked&cd=0%7C0%7C0%7C3&cv=1&br=1388&bt=694&bti=NDU3ZjAwOg%3D%3D&cs=2&ds=6&ft=_rKBMBnZq8ZmoJxv.Q_vjmz8sAhLrus&mime_type=video_mp4&qs=11&rc=aDY7O2k8Omk4Ojw6OWU8aEBpNWY4N2g6OjNlZTM7N2RmNkAxYTQvNDUtNV4xNS9iYjUtYSMxNWIxNi40NmMxLjRfXi8wcw%3D%3D&btag=e00008000&expire=1697391770&l=2023101317423689D9BC71D9A0DA246649&ply_type=2&policy=2&signature=07cbea9402199f140ab0000b51909708&tk=tt_chain_token" ], "QualityType": 28 }, "codecType": "h264", "cover": "https://p16-sign-va.tiktokcdn.com/obj/tos-maliva-p-0068/reg02/2016/07/05/02/9d2721f5-2c55-496b-857b-1cc2a3fd1bf7.jpg?x-expires=1697389200&x-signature=iCyTj6EZbj0nNgzqwK4myJNaaOw%3D", "definition": "540p", "downloadAddr": "https://v16-webapp-prime.us.tiktok.com/video/tos/useast5/tos-useast5-ve-0068c004-tx/f2d29f37773d4e86a1bc9187e7e2fe16/?a=1988&ch=0&cr=3&dr=0&lr=tiktok_m&cd=0%7C0%7C0%7C3&cv=1&br=594&bt=297&bti=NDU3ZjAwOg%3D%3D&cs=2&ds=6&ft=_rKBMBnZq8ZmoJxv.Q_vjmz8sAhLrus&mime_type=video_mp4&qs=5&rc=N2Y4aGg1aWdpPGg6NGk6aUBpNWY4N2g6OjNlZTM7N2RmNkBjNGA2XjNfXjUxNi4wYTU2YSMxNWIxNi40NmMxLjRfXi8wcw%3D%3D&btag=e00008000&expire=1697391770&l=2023101317423689D9BC71D9A0DA246649&ply_type=2&policy=2&signature=243ac7274405ee16fd0c52db8c1846b2&tk=tt_chain_token", "duration": 14, "dynamicCover": "https://p16-sign-va.tiktokcdn.com/obj/tos-maliva-p-0068/reg02/2016/07/05/02/98f2d2ac-6d35-4804-888f-38fe6dfa9896.webp?x-expires=1697389200&x-signature=CcN8LX4NAv1NIiwcQYrsZSprM8Y%3D", "encodeUserTag": "", "encodedType": "original", "format": "mp4", "height": 960, "id": "114558579130482688", "originCover": "https://p16-sign-va.tiktokcdn.com/obj/tos-maliva-p-0068/reg02/2016/07/05/02/9d2721f5-2c55-496b-857b-1cc2a3fd1bf7.jpg?x-expires=1697389200&x-signature=iCyTj6EZbj0nNgzqwK4myJNaaOw%3D", "playAddr": "https://v16-webapp-prime.us.tiktok.com/video/tos/useast5/tos-useast5-v-0068-tx/reg02/2016/07/05/02/26dd78f2-da8b-4748-96b7-31c2b5e68b12.mp4/?a=1988&ch=0&cr=3&dr=0&lr=unwatermarked&cd=0%7C0%7C0%7C3&cv=1&br=3750&bt=1875&bti=NDU3ZjAwOg%3D%3D&cs=0&ds=6&ft=_rKBMBnZq8ZmoJxv.Q_vjmz8sAhLrus&mime_type=video_mp4&qs=13&rc=NWY4N2g6OjNlZTM7N2RmNkBpNWY4N2g6OjNlZTM7N2RmNkAxNWIxNi40NmMxLjRfXi8wYSMxNWIxNi40NmMxLjRfXi8wcw%3D%3D&btag=e00008000&expire=1697391770&l=2023101317423689D9BC71D9A0DA246649&ply_type=2&policy=2&signature=b01f5145c9a98f45eda04a7ca63092b1&tk=tt_chain_token", "ratio": "540p", "reflowCover": "https://p16-sign-va.tiktokcdn.com/tos-maliva-p-0068/reg02/2016/07/05/02/9d2721f5-2c55-496b-857b-1cc2a3fd1bf7.jpg~tplv-photomode-video-cover:480:480.jpeg?x-expires=1697389200&x-signature=FfQhs56LRTY%2F1rqWiZ9foLraV8s%3D", "shareCover": [ "" ], "size": 3513008, "videoQuality": "original", "volumeInfo": { }, "width": 540, "zoomCover": { "240": "https://p16-sign-va.tiktokcdn.com/tos-maliva-p-0068/reg02/2016/07/05/02/9d2721f5-2c55-496b-857b-1cc2a3fd1bf7.jpg~tplv-photomode-zoomcover:240:240.jpeg?x-expires=1697389200&x-signature=taR%2FV0Pw5kc5kh1kAPPUowtbwUo%3D", "480": "https://p16-sign-va.tiktokcdn.com/tos-maliva-p-0068/reg02/2016/07/05/02/9d2721f5-2c55-496b-857b-1cc2a3fd1bf7.jpg~tplv-photomode-zoomcover:480:480.jpeg?x-expires=1697389200&x-signature=4SiwY8Khs13ney4jD9UhBIq2oWA%3D", "720": "https://p16-sign-va.tiktokcdn.com/tos-maliva-p-0068/reg02/2016/07/05/02/9d2721f5-2c55-496b-857b-1cc2a3fd1bf7.jpg~tplv-photomode-zoomcover:720:720.jpeg?x-expires=1697389200&x-signature=hhEuaX5h%2FsshVXQgZxH%2BYKZRVv0%3D", "960": "https://p16-sign-va.tiktokcdn.com/tos-maliva-p-0068/reg02/2016/07/05/02/9d2721f5-2c55-496b-857b-1cc2a3fd1bf7.jpg~tplv-photomode-zoomcover:960:960.jpeg?x-expires=1697389200&x-signature=s6XTua8oCOfP7m9UyYHc%2Bw7nEtE%3D" } }, "vl1": false } ``` ``` -------------------------------- ### Get Hashtag Posts by Name Source: https://tikapi.io/documentation/index Retrieves posts associated with a given hashtag name. This is the initial request to get hashtag information, including its ID for subsequent requests. ```APIDOC ## GET /public/hashtag ### Description Retrieves posts associated with a given hashtag name. Use this endpoint first to obtain the hashtag ID. ### Method GET ### Endpoint https://api.tikapi.io/public/hashtag ### Parameters #### Query Parameters - **name** (string) - Required - The name of the hashtag. - **count** (number) - Optional - Maximum number of items to retrieve per request. Defaults to 30. - **cursor** (string) - Optional - The starting point for pagination. Use the `cursor` from the previous response for subsequent requests. - **country** (string) - Optional - ISO code of the country to proxy the request from (e.g., us, ca, gb). ### Request Example ``` GET /public/hashtag?name=funnycats&count=10&country=us ``` ### Response #### Success Response (200) - **data** (object) - Contains the list of posts and challenge information. - **posts** (array) - List of posts. - **challengeInfo** (object) - Information about the hashtag. - **challenge** (object) - **id** (string) - The unique ID of the hashtag. - **title** (string) - The name of the hashtag. - **desc** (string) - Description of the hashtag. - **cover** (string) - URL of the hashtag cover image. - **stats** (object) - Statistics related to the hashtag. - **message** (string) - Empty if successful. - **status** (string) - Indicates the status of the request (e.g., "success"). - **statusCode** (number) - Status code of the request (0 for success). #### Response Example (Success) ```json { "data": { "posts": [ { "id": "7287306862427426091", "cover": "https://...", "definition": "540p", "downloadAddr": "https://...", "duration": 16, "dynamicCover": "https://...", "encodeUserTag": "", "encodedType": "normal", "format": "mp4", "height": 1024, "originCover": "https://...", "playAddr": "https://...", "ratio": "540p", "videoQuality": "normal", "volumeInfo": { "Loudness": -23.2, "Peak": 0.40738 }, "width": 576, "zoomCover": { "240": "https://...", "480": "https://...", "720": "https://...", "960": "https://..." } } ], "challengeInfo": { "challenge": { "id": "7287306862427426091", "title": "funnycats", "desc": "Funny cat videos", "cover": "https://..." }, "stats": { "videoCount": 1000000, "viewCount": 5000000000 } } }, "log_pb": { "impr_id": "202310131742238D61BD86860F15203FBC" }, "message": "", "status": "success", "statusCode": 0, "status_code": 0 } ``` #### Error Response (403) - **message** (string) - Description of the error. - **status** (string) - "error" - **statusCode** (number) - Non-zero error code. #### Response Example (Error) ```json { "message": "Invalid API key or permissions.", "status": "error", "statusCode": 403 } ``` ``` -------------------------------- ### Get User Explore Posts - JavaScript Source: https://tikapi.io/documentation/index This JavaScript snippet demonstrates how to use the TikAPI to fetch trending posts from the 'For You' section. It initializes the TikAPI with an API key and a user account key, then calls the `explore` method on the `User.posts` object. The response is logged to the console, with error handling included. ```javascript import TikAPI from 'tikapi'; const api = TikAPI("myAPIKey"); const User = new api.user({ accountKey: "DemoAccountKeyTokenSeHYGXDfd4SFD320Sc39Asd0Sc39A" }); (async function(){ try{ let response = await User.posts.explore(); console.log(response.json); } catch(err){ console.log(err?.statusCode, err?.message, err?.json) } })(); ```