Russell-Newton / TikTokPy

Extract data from TikTok without needing any login information or API keys.
https://pypi.org/project/tiktokapipy/
MIT License
214 stars 28 forks source link

[QUESTION] How to retrieve more than 10 videos ? #51

Closed Fabien-desablens closed 1 year ago

Fabien-desablens commented 1 year ago

Hello,

pip freeze | findstr tiktokapipy tiktokapipy==0.2.0
pip freeze | findstr pydantic pydantic==2.0.1 pydantic_core==2.0.2

I just switched to v 0.2 but I can't return more than 10 videos, please how can I return all user's videos ?

from tiktokapipy.api import TikTokAPI

# Fonction pour récupérer les vidéos d'un compte TikTok spécifié
def get_videos(username):
    videos = []
    with TikTokAPI() as api:
        user = api.user(username)
        for video in user.videos:
            videos.append({
                "video_id": video.id,
                "views": video.stats.play_count,
                "likes": video.stats.digg_count
            })
    return videos

# Fonction pour calculer l'engagement d'une vidéo (pourcentage de likes par rapport au nombre de vues)
def calculate_engagement(video):
    if video["views"] > 0:
        engagement = (video["likes"] / video["views"]) * 100
    else:
        engagement = 0
    return engagement

username = ""  

# Récupérer les vidéos du compte TikTok spécifié avec les nombres de vues et de likes
videos = get_videos(username)

# Calculer l'engagement de chaque vidéo et ajouter la valeur dans un nouveau champ "engagement"
for video in videos:
    video["engagement"] = calculate_engagement(video)

# Trier les vidéos par engagement (du plus élevé au plus faible)
videos_sorted = sorted(videos, key=lambda x: x["engagement"], reverse=True)

# Afficher le pourcentage d'engagement et le lien vers les vidéos classées par engagement
for video in videos_sorted:
    engagement = video["engagement"]
    video_id = video["video_id"]
    link = f"https://www.tiktok.com/@{username}/video/{video_id}"
    print(f"Engagement: {engagement}%")
    print(f"Video Link: {link}")
    print()

I tested several users and it returns 10 videos, what's wrong with my code ? Thanks

Russell-Newton commented 1 year ago

This seems to have been a latent bug in release 0.2.0. It should now be fixed in 0.2.0post1. Let me know if it works for you, and we can close this issue.

Fabien-desablens commented 1 year ago

Thanks. It's now working fine. By the way, tks for the api, I've tested few and it's the only one that works great.

Russell-Newton commented 1 year ago

I'm glad it works well for you. I'm closing this issue as resolved.