diff --git a/README.md b/README.md index 969b95ee..368c7299 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ Consider sponsoring me [here](https://github.com/sponsors/davidteather) - [get_Video_By_DownloadURL](#the-get_video_by_downloadurl-method) - [get_Video_By_Url](#the-get_video_by_url-method) - [get_Video_No_Watermark](#the-get_video_no_watermark-method) + - [userLiked](#the-userliked-method) + - [userLikedbyUsername](#the-userlikedbyusername-method) - [Built With](#built-with) - [Authors](#authors) - [License](#license) @@ -224,6 +226,20 @@ Returns trending hashtags (challenges) shown on the side at tiktok's trending pa def discoverHashtags(self, language='en', proxy=None) ``` +##### The userLiked Method + +Returns a list of a given user's liked TikToks. Returns a length of 0 if private list. +``` +userLiked(self, userID, secUID, count=30, language='en', region='US', proxy=None) +``` + +### The userLikedbyUsername Method + +Returns a list of a given user's liked TikToks. Returns a length of 0 if private list. +``` +userLikedbyUsername(self, username, count=30, proxy=None, language='en', region='US') +``` + ##### The getSuggestedUsersbyID Method This method gets suggested users for a given userid. diff --git a/TikTokApi/__pycache__/browser.cpython-36.pyc b/TikTokApi/__pycache__/browser.cpython-36.pyc index 2d8979c3..9bae6bba 100644 Binary files a/TikTokApi/__pycache__/browser.cpython-36.pyc and b/TikTokApi/__pycache__/browser.cpython-36.pyc differ diff --git a/TikTokApi/__pycache__/tiktok.cpython-36.pyc b/TikTokApi/__pycache__/tiktok.cpython-36.pyc index 0553a75e..cdb43e5e 100644 Binary files a/TikTokApi/__pycache__/tiktok.cpython-36.pyc and b/TikTokApi/__pycache__/tiktok.cpython-36.pyc differ diff --git a/TikTokApi/tiktok.py b/TikTokApi/tiktok.py index ee068484..7cfee3ea 100644 --- a/TikTokApi/tiktok.py +++ b/TikTokApi/tiktok.py @@ -14,6 +14,7 @@ class TikTokApi: # The TikTokapi class constructor # def __init__(self, debug=False): + self.debug = debug if debug: print("Class initialized") @@ -98,10 +99,11 @@ def trending(self, count=30, language='en', proxy=None): return response[:count] + # # Gets a specific user's tiktoks # - def userPosts(self, userID, secUID, count=30, language='en', proxy=None): + def userPosts(self, userID, secUID, count=30, language='en', region='US', proxy=None): response = [] maxCount = 99 maxCursor = 0 @@ -112,8 +114,8 @@ def userPosts(self, userID, secUID, count=30, language='en', proxy=None): else: realCount = maxCount - api_url = "https://m.tiktok.com/api/item_list/?count={}&id={}&type=1&secUid={}&maxCursor={}&minCursor=0&sourceType=8&appId=1233®ion=US&language={}&verifyFp=".format( - str(realCount), str(userID), str(secUID), str(maxCursor), str(language)) + api_url = "https://m.tiktok.com/api/item_list/?count={}&id={}&type=1&secUid={}&maxCursor={}&minCursor=0&sourceType=8&appId=1233®ion={}&language={}&verifyFp=".format( + str(realCount), str(userID), str(secUID), str(maxCursor), str(region), str(language)) b = browser(api_url, proxy=proxy) res = self.getData(api_url, b.signature, b.userAgent, proxy=proxy) @@ -128,14 +130,60 @@ def userPosts(self, userID, secUID, count=30, language='en', proxy=None): maxCursor = res['maxCursor'] return response[:count] - + # # Gets a specific user's tiktoks by username # - def byUsername(self, username, count=30, proxy=None): + def byUsername(self, username, count=30, proxy=None, language='en', region='US'): + data = self.getUserObject(username, proxy=proxy) + return self.userPosts(data['id'], data['secUid'], count=count, proxy=proxy, language=language, region=region) + + # + # Gets a user's liked posts + # + def userLiked(self, userID, secUID, count=30, language='en', region='US', proxy=None): + response = [] + maxCount = 99 + maxCursor = 0 + + while len(response) < count: + if count < maxCount: + realCount = count + else: + realCount = maxCount + + api_url = "https://m.tiktok.com/api/item_list/?count={}&id={}&type=2&secUid={}&maxCursor={}&minCursor=0&sourceType=9&appId=1233®ion={}&language={}&verifyFp=".format( + str(realCount), str(userID), str(secUID), str(maxCursor), str(region), str(language)) + b = browser(api_url, proxy=proxy) + res = self.getData(api_url, b.signature, b.userAgent, proxy=proxy) + + try: + res['items'] + except: + if self.debug: + print("Most Likely User's List is Empty") + return [] + + for t in res['items']: + response.append(t) + + if not res['hasMore']: + print("TikTok isn't sending more TikToks beyond this point.") + return response + + realCount = count-len(response) + maxCursor = res['maxCursor'] + + return response[:count] + + # + # Gets a specific user's likes by username + # + + def userLikedbyUsername(self, username, count=30, proxy=None, language='en', region='US'): data = self.getUserObject(username, proxy=proxy) - return self.userPosts(data['id'], data['secUid'], count=count, proxy=proxy) + return self.userLiked(data['id'], data['secUid'], count=count, proxy=proxy, language=language, region=region) # # Gets tiktoks by music ID diff --git a/setup.py b/setup.py index 26fb77c4..a7b4d5d1 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name = 'TikTokApi', packages = ['TikTokApi'], - version = '3.1.8', + version = '3.1.9', license='MIT', description = 'The Unofficial TikTok API Wrapper in Python 3.', author = 'David Teather', diff --git a/tests/test_user.py b/tests/test_user.py index 13743bed..82f2c0fe 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -8,3 +8,5 @@ def test_user(): assert abs(len(api.userPosts(userID="5058536", secUID="MS4wLjABAAAAoRsCq3Yj6BtSKBCQ4rf3WQYxIaxe5VetwJfYzW_U5K8", count=5))-5) <= 1 assert abs(len(api.userPosts(userID="5058536", secUID="MS4wLjABAAAAoRsCq3Yj6BtSKBCQ4rf3WQYxIaxe5VetwJfYzW_U5K8", count=10))-10) <= 1 assert abs(len(api.userPosts(userID="5058536", secUID="MS4wLjABAAAAoRsCq3Yj6BtSKBCQ4rf3WQYxIaxe5VetwJfYzW_U5K8", count=30))-30) <= 1 + + # assert len(api.userLikedbyUsername(username="", count=30)) == 30 \ No newline at end of file