Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user like #1043

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
project = "TikTokAPI"
copyright = "2023, David Teather"
author = "David Teather"
release = "v6.0.1"
release = "v6.1.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/main/usage/configuration.html#general-configuration
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors:
orcid: "https://orcid.org/0000-0002-9467-4676"
title: "TikTokAPI"
url: "https://github.com/davidteather/tiktok-api"
version: 6.0.1
date-released: 2023-8-8
version: 6.1.0
date-released: 2023-8-18
54 changes: 50 additions & 4 deletions TikTokApi/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,59 @@ async def videos(self, count=30, cursor=0, **kwargs) -> Iterator[Video]:

cursor = resp.get("cursor")

def liked(self, count: int = 30, cursor: int = 0, **kwargs) -> Iterator[Video]:
async def liked(self, count: int = 30, cursor: int = 0, **kwargs) -> Iterator[Video]:
"""
Returns a dictionary listing TikToks that a given a user has liked.
Returns a user's liked posts if public.

TODO: Not currently implemented
Args:
count (int): The amount of recent likes you want returned.
cursor (int): The the offset of likes from 0 you want to get.

Returns:
async iterator/generator: Yields TikTokApi.video objects.

Raises:
InvalidResponseException: If TikTok returns an invalid response, the user's likes are private, or one we don't understand.

Example Usage:
.. code-block:: python

async for like in api.user(username="davidteathercodes").liked():
# do something
"""
raise NotImplementedError
sec_uid = getattr(self, "sec_uid", None)
if sec_uid is None or sec_uid == "":
await self.info(**kwargs)

found = 0
while found < count:
params = {
"secUid": self.sec_uid,
"count": 35,
"cursor": cursor,
}

resp = await self.parent.make_request(
url="https://www.tiktok.com/api/favorite/item_list",
params=params,
headers=kwargs.get("headers"),
session_index=kwargs.get("session_index"),
)

if resp is None:
raise InvalidResponseException(
resp, "TikTok returned an invalid response."
)

for video in resp.get("itemList", []):
yield self.parent.video(data=video)
found += 1

if not resp.get("hasMore", False):
return

cursor = resp.get("cursor")


def __extract_from_data(self):
data = self.as_dict
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=setuptools.find_packages(),
version="6.0.1",
version="6.1.0",
license="MIT",
description="The Unofficial TikTok API Wrapper in Python 3.",
author="David Teather",
Expand Down
3 changes: 1 addition & 2 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ async def test_user_videos():

@pytest.mark.asyncio
async def test_user_likes():
pytest.skip("Not implemented yet")
api = TikTokApi()
async with api:
await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
user = api.user(username=username, sec_uid=sec_uid, user_id=user_id)
user = api.user(username="publicliketest", sec_uid="MS4wLjABAAAAHjhwCIwmvzVZfRrDAZ2aZy74LciLnoyaPfM2rrX9N7bwbWMFuwTFG4YrByYvsH5c")

count = 0
async for video in user.liked(count=30):
Expand Down