Skip to content

Commit

Permalink
Merge pull request #145 from davidteather/nightly
Browse files Browse the repository at this point in the history
V3.1.9
  • Loading branch information
davidteather authored Jun 12, 2020
2 parents 6057968 + 0149da5 commit 3b56d93
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 7 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
Binary file modified TikTokApi/__pycache__/browser.cpython-36.pyc
Binary file not shown.
Binary file modified TikTokApi/__pycache__/tiktok.cpython-36.pyc
Binary file not shown.
60 changes: 54 additions & 6 deletions TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TikTokApi:
# The TikTokapi class constructor
#
def __init__(self, debug=False):
self.debug = debug
if debug:
print("Class initialized")

Expand Down Expand Up @@ -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
Expand All @@ -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&region=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&region={}&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)

Expand All @@ -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&region={}&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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3b56d93

Please sign in to comment.