This document will guide you on how to use the Apify Actor TikTok Comment API (https://apify.com/novi/tiktok-comment-api) to effortlessly gather comments from TikTok videos using Python programming language.
What are Apify and Actors?
Apify is a cloud-based platform designed for web automation. It provides a suite of tools and services, with Actors being a core component.
Actors in Apify are pre-built applications designed to perform specific web automation tasks. Think of them as pre-programmed web "robots" that save you the time and effort of building complex web scraping or automation scripts from scratch.
Benefits of using Actors:
- Time-saving: Eliminate the need to write intricate code for web tasks like data extraction.
- User-friendly: Actors are generally designed for ease of use, even for those with limited programming experience.
- Reliable: Apify ensures Actors are stable and deliver accurate data.
- Versatile: A wide range of Actors are available for diverse purposes, from data scraping and website monitoring to social media automation.
Apify Actor TikTok Comment API
The Apify Actor TikTok Comment API (https://apify.com/novi/tiktok-comment-api) is a specialized Actor developed by Apify for automatically extracting comments from TikTok videos. This Actor is invaluable for market researchers, data analysts, and anyone interested in monitoring user sentiment on TikTok.
Key Features of the Actor:
- Bulk Comment Extraction: Easily retrieve thousands of comments from single or multiple TikTok videos.
- Structured Data: Comment data is returned in a structured JSON format, simplifying processing and analysis.
- Customizable: Input parameters allow you to filter and tailor comment collection to your specific needs.
- Maintained and Reliable: The Actor is regularly updated to ensure compatibility with TikTok's platform changes and maintain stable operation.
Step-by-Step Guide: Using TikTok Comment API Actor with Python
To utilize this Actor within your Python code, follow these steps:
Step 1: Install the Apify Client Library
First, you need to install the apify-client library for Python. Open your terminal or command prompt and run:
pip install apify-client
Step 2: Obtain your Apify API token
An Apify account is required to use Actors. If you don't have one, visit https://apify.com/ and sign up for free.
Once logged in, your Apify API token can be found on the Settings page of your account. Keep this token secure as you'll need it for authentication when using the Actor.
Step 3: Write your Python code
Below is a basic Python code example demonstrating how to use the TikTok Comment API Actor:
from apify_client import ApifyClient
# Replace 'YOUR_API_TOKEN' with your actual Apify API token
APIFY_API_TOKEN = "YOUR_API_TOKEN"
# Initialize the Apify Client
apify_client = ApifyClient(APIFY_API_TOKEN)
# Actor input with correct schema
actor_input = {
"url": "https://www.tiktok.com/@thierry_baudet/video/7402914280741424416", # Replace with the TikTok video URL you want to scrape comments from
"limit": 1000, # Optional: Maximum number of comments to retrieve
"proxyConfiguration": {
"useApifyProxy": False # Optional: Proxy configuration. Set to true to use Apify proxy (paid)
}
}
# Run the Actor and wait for the result
run = apify_client.actor("novi/tiktok-comment-api").call(run_input=actor_input)
# Fetch and print Actor results
for item in run.dataset().iterate_items():
print(item)
Code Explanation (Updated):
from apify_client import ApifyClient: Imports theapify-clientlibrary.APIFY_API_TOKEN = "YOUR_API_TOKEN": Defines theAPIFY_API_TOKENvariable, replacing"YOUR_API_TOKEN"with your API token obtained in Step 2.apify_client = ApifyClient(APIFY_API_TOKEN): Initializes anApifyClientobject to interact with the Apify API.actor_input = {...}: Defines the input for the Actor with the correct schema."url": "https://www.tiktok.com/@thierry_baudet/video/7402914280741424416": Replace the example URL with the URL of the TikTok video."limit": 1000: (Optional) Specifies the maximum number of comments to retrieve."proxyConfiguration": { "useApifyProxy": False }: (Optional) Proxy configuration."useApifyProxy": Falsemeans not to use Apify proxy. If you set it totrue, it will use Apify proxy service (which may incur costs).
run = apify_client.actor("novi/tiktok-comment-api").call(run_input=actor_input): Executes the Actor named"novi/tiktok-comment-api"with the definedactor_input. Thecall()function sends the request to Apify and waits for the Actor to complete its execution.for item in run.dataset().iterate_items():: Iterates through each data item in the dataset returned by the Actor. Each item represents a TikTok comment.print(item): Prints the information for each comment.
Step 4: Execute the code and view results
- Save the code to a Python file (e.g.,
tiktok_scraper.py). - Open your terminal or command prompt, navigate to the directory containing the Python file, and run:
python tiktok_scraper.py
Code will run and output the collected comments from the specified TikTok video. The results are displayed in JSON format.
Output Format (JSON)
The Actor returns comment data as an array of JSON objects. Each object in the array represents a single comment and includes the following fields:
author_pin(boolean): Indicates if the comment is pinned by the author.aweme_id(string): The ID of the TikTok video.cid(string): Unique ID of the comment.collect_stat(integer): Likely related to collection statistics (needs further clarification from Apify documentation if available).comment_language(string): Language code of the comment (e.g., "en" for English).create_time(integer): Timestamp of comment creation in Unix epoch seconds.digg_count(integer): Number of likes for the comment.is_author_digged(boolean): Indicates if the current user has liked the comment (likely depends on authentication context, may not be relevant for general scraping).label_list(array|null): Labels associated with the comment (if any).no_show(boolean): Indicates if the comment is hidden or not shown.reply_comment(object|null): Information about the comment being replied to (if it's a reply).reply_comment_total(integer): Total number of replies to this comment.reply_id(string): ID of the comment being replied to (if applicable). "0" if it's a top-level comment.reply_to_reply_id(string): ID of the comment being replied to in a nested reply chain. "0" if not a nested reply.share_info(object): Information related to sharing the comment.acl(object): Access control list for sharing.desc(string): Description for sharing.title(string): Title for sharing.url(string): URL for sharing the comment.
status(integer): Status code of the comment (e.g., 1 might indicate "visible").stick_position(integer): Position of the comment if it's stickied/pinned. 0 if not pinned.text(string): The text content of the comment.text_extra(array): Entities mentioned or linked within the comment text (e.g., hashtags, user mentions).end(integer): End index of the entity in the text.hashtag_id(string): ID of the hashtag (if applicable).hashtag_name(string): Name of the hashtag (if applicable).sec_uid(string): Secure user ID of the mentioned user.start(integer): Start index of the entity in the text.user_id(string): User ID of the mentioned user.
trans_btn_style(integer): Style of translation button (if applicable).user(object): Information about the comment author. This is a nested JSON object containing various user details (avatar URLs, usernames, follower counts, etc.). Refer to the example output for the detailed structure.user_buried(boolean): Indicates if the user is buried/hidden (needs clarification, likely internal TikTok feature).user_digged(integer): Indicates if the current user has liked the comment author (likely depends on authentication context, may not be relevant for general scraping).
Example Output (Array of JSON objects):
[
{
"author_pin": false,
"aweme_id": "7211250685902359850",
"cid": "7217494551149101851",
"collect_stat": 0,
"comment_language": "en",
"create_time": 1680453949,
"digg_count": 23,
"is_author_digged": false,
"label_list": null,
"no_show": false,
"reply_comment": null,
"reply_comment_total": 5,
"reply_id": "0",
"reply_to_reply_id": "0",
"share_info": {
"acl": {
"code": 0,
"extra": "{}"
},
"desc": "šµš± Kasia š®šø's comment: Look it for @Marika Christman . She is doing the best outfits for you. Check it out.",
"title": "The rehearsal no one saw. Love you all, thanks for being so supportive of a song that means so much to me ❤️",
"url": "https://www.tiktok.com/@ladygaga/video/7211250685902359850?_d=e80jjb2j1hfl54&_r=1&comment_author_id=7046867863550247941&preview_pb=0&share_comment_id=7217494551149101851&share_item_id=7211250685902359850&sharer_language=en&source=h5_m&u_code=0"
},
"status": 1,
"stick_position": 0,
"text": "Look it for @Marika Christman . She is doing the best outfits for you. Check it out.",
"text_extra": [
{
"end": 29,
"hashtag_id": "",
"hashtag_name": "",
"sec_uid": "MS4wLjABAAAArXhs1fvcchkAbFNXpJZcD4BSJv7EmPFYcLpK2llb0Fq-K5BFkijKYQlDnHoKL1F6",
"start": 12,
"user_id": "7038949358691910662"
}
],
"trans_btn_style": 0,
"user": {
"accept_private_policy": false,
"account_labels": null,
"account_region": "",
"ad_cover_url": null,
"advance_feature_item_order": null,
"advanced_feature_info": null,
"apple_account": 0,
"authority_status": 0,
"avatar_168x168": {
"height": 720,
"uri": "168x168/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7",
"url_list": [
"https://p16-amd-va.tiktokcdn.com/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~tplv-tiktok-shrink:64:64.webp?s=COMMENT_LIST&se=false&sh=64_64&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18",
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_168x168.webp?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18",
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_168x168.jpeg?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18"
],
"width": 720
},
"avatar_300x300": {
"height": 720,
"uri": "300x300/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7",
"url_list": [
"https://p16-amd-va.tiktokcdn.com/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~tplv-tiktok-shrink:64:64.webp?s=COMMENT_LIST&se=false&sh=64_64&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18",
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_300x300.webp?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18",
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_300x300.jpeg?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18"
],
"width": 720
},
"avatar_larger": {
"height": 720,
"uri": "1080x1080/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7",
"url_list": [
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_1080x1080.webp?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18",
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_1080x1080.jpeg?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18"
],
"width": 720
},
"avatar_medium": {
"height": 720,
"uri": "720x720/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7",
"url_list": [
"https://p16-amd-va.tiktokcdn.com/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~tplv-tiktok-shrink:64:64.webp?s=COMMENT_LIST&se=false&sh=64_64&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18",
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_720x720.webp?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18",
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_720x720.jpeg?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18"
],
"width": 720
},
"avatar_thumb": {
"height": 720,
"uri": "100x100/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7",
"url_list": [
"https://p16-amd-va.tiktokcdn.com/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~tplv-tiktok-shrink:64:64.webp?s=COMMENT_LIST&se=false&sh=64_64&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18",
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_100x100.webp?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18",
"https://p16-amd-va.tiktokcdn.com/img/tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7~c5_100x100.jpeg?s=COMMENT_LIST&se=false&sh=&sc=avatar&l=20230514065113FFB5EBB0D8A8D784DD18"
],
"width": 720
},
"avatar_uri": "tos-maliva-avt-0068/7818f08ae60f5417edede76314c0baa7",
"aweme_count": 0,
"bind_phone": "",
"bold_fields": null,
"can_message_follow_status_list": null,
"can_set_geofencing": null,
"cha_list": null,
"comment_filter_status": 0,
"comment_setting": 0,
"commerce_user_level": 0,
"cover_url": [
{
"height": 720,
"uri": "musically-maliva-obj/1612555907887110",
"url_list": [
"https://p16-amd-va.tiktokcdn.com/obj/musically-maliva-obj/1612555907887110"
],
"width": 720
}
],
"create_time": 0,
"custom_verify": "",
"cv_level": "",
"download_prompt_ts": 1641158568,
"download_setting": 0,
"duet_setting": 0,
"enterprise_verify_reason": "",
"events": null,
"favoriting_count": 0,
"fb_expire_time": 0,
"follow_status": 0,
"follower_count": 0,
"follower_status": 0,
"followers_detail": null,
"following_count": 0,
"friends_status": 0,
"geofencing": null,
"google_account": "",
"has_email": false,
"has_facebook_token": false,
"has_insights": false,
"has_orders": false,
"has_twitter_token": false,
"has_youtube_token": false,
"hide_search": false,
"homepage_bottom_toast": null,
"ins_id": "katarzyna.krupinska82",
"is_ad_fake": false,
"is_block": false,
"is_discipline_member": false,
"is_phone_binded": false,
"is_star": false,
"item_list": null,
"language": "pl",
"live_agreement": 0,
"live_commerce": false,
"live_verify": 0,
"matched_friend_available": false,
"mention_status": 1,
"mutual_relation_avatars": null,
"need_points": null,
"need_recommend": 0,
"nickname": "šµš± Kasia š®šø",
"platform_sync_info": null,
"prevent_download": false,
"react_setting": 0,
"region": "IS",
"relative_users": null,
"room_id": 0,
"search_highlight": null,
"sec_uid": "MS4wLjABAAAAZl-oKhIJ9Odmr5H0Nw0rAxgPJgZ16uWIm5pZYxxiJiWcDpPmzOTOu4NbYkgzj9p7",
"secret": 0,
"shield_comment_notice": 0,
"shield_digg_notice": 0,
"shield_edit_field_info": null,
"shield_follow_notice": 0,
"short_id": "0",
"show_image_bubble": false,
"signature": "šµš±\nš®šø",
"special_account": {
"special_account_list": null
},
"special_lock": 1,
"status": 1,
"stitch_setting": 0,
"total_favorited": 0,
"tw_expire_time": 0,
"twitter_id": "",
"twitter_name": "",
"type_label": null,
"uid": "7046867863550247941",
"unique_id": "katie.kru",
"unique_id_modify_time": 1684047073,
"user_canceled": false,
"user_mode": 1,
"user_period": 0,
"user_profile_guide": null,
"user_rate": 1,
"user_tags": null,
"verification_type": 0,
"verify_info": "",
"video_icon": {
"height": 720,
"uri": "",
"url_list": [],
"width": 720
},
"white_cover_url": null,
"with_commerce_entry": false,
"with_shop_entry": false,
"youtube_channel_id": "",
"youtube_channel_title": "",
"youtube_expire_time": 0
},
"user_buried": false,
"user_digged": 0
}
]
You can customize the code to save the results to a file, analyze the data, or perform other operations according to your needs.
Conclusion
Apify Actor TikTok Comment API is a powerful and easy-to-use tool for collecting comments from TikTok videos. Combined with the Apify Client library for Python, you can easily automate this process and efficiently collect comment data for analysis and research purposes.
Hope this guide is helpful for you! If you have any questions, don't hesitate to ask.
Comments
Post a Comment