from pytiktokbot import TikTokApi import os api = TikTokApi.get_instance(custom_verifyFp=os.environ.get("verifyFp", None), use_test_endpoints=True) def unique_count(tiktoks): tmp = [] for t in tiktoks: if t["id"] not in tmp: tmp.append(t["id"]) return tmp def test_hashtag(): assert len(api.byHashtag("funny", 5)) == 5 assert len(api.byHashtag("funny", 10)) == 10 assert len(api.byHashtag("funny", 20)) == 20 # Grant A Little Lenience of at most a 15 difference assert abs(len(unique_count(api.byHashtag("funny", 500))) - 500) <= 15 def test_non_latin1(): assert len(api.byHashtag("селфи", count=3)) == 3
from pytiktokbot import TikTokApi # Starts pytiktokbot api = TikTokApi.get_instance() # The Number of trending TikToks you want to be displayed results = 10 # Returns a list of dictionaries of the trending object userPosts = api.userPosts( "6745191554350760966", "MS4wLjABAAAAM3R2BtjzVT-uAtstkl2iugMzC6AtnpkojJbjiOdDDrdsTiTR75-8lyWJCY5VvDrZ", 30, ) # Loops over every tiktok for tiktok in userPosts: # Prints the text of the tiktok print(tiktok["desc"]) print(len(userPosts))
from datetime import datetime from pytiktokbot import TikTokApi api = TikTokApi(debug=True) def printPage(page): """Just prints out each post with timestamp and description""" for post in page: print("{}: {}".format(datetime.fromtimestamp(post["createTime"]), post["desc"])) count = 20 username = "******" # count and list all of the posts for a given user with the pager total = 0 pager = api.getUserPager(username, page_size=count) for page in pager: printPage(page) total += len(page) print("{} has {} posts".format(username, total)) all_posts = total # List all of the posts for a given user after a certain date APR_24 = 1587757438000 # 2020-04-24 15:43:58 to be precise. Must be ms-precision UNIX timestamp