instagrapi icon indicating copy to clipboard operation
instagrapi copied to clipboard

Discrepancy in Video View Counts with instagrapi

Open ironhost opened this issue 1 year ago • 4 comments

Hello Developer's Team,

I hope this message finds you well. I've been using the instagrapi library (version 4.10.1) for some data extraction tasks, specifically to retrieve video views from Instagram posts. However, I've noticed a discrepancy in the numbers being returned by the library and the actual view counts displayed on Instagram. For instance, a video with 22,536 views on Instagram was reported to have only 11,368 views when fetched using instagrapi.

I've followed the library documentation and ensured that my implementation is correct. I wonder if this is a known issue or if there's something I might be missing. Is there any particular reason for this discrepancy? And do you have any advice or solution to address this?

I appreciate the great work you've done with instagrapi and would be grateful for any assistance or insights you can provide on this matter.

Thank you in advance for your time and support.

Best regards, alireza

ironhost avatar Oct 18 '23 06:10 ironhost

my code is :

from instagrapi import Client import time import jdatetime from datetime import datetime import pytz

def get_instagram_data(username, cl): user = cl.user_info_by_username(username)

print(f"\nAnalysis for: {username}")
print(f"Followers Count: {user.follower_count}")
print(f"Post Count: {user.media_count}")

stories = cl.user_stories(user.pk)
print(f"Active Stories Count: {len(stories) if stories else 0}")

# Retrieve the recent media for the user and limit to the desired number
medias = cl.user_medias(user.pk)[:5]
post_num = user.media_count  #  Start with the total post count

for idx, media in enumerate(medias):
    # Convert to Tehran timezone
    tehran = pytz.timezone('Asia/Tehran')
    dt_object_tehran = media.taken_at.astimezone(tehran)
    
    # Convert date and time to Shamsi (Jalali)
    jalali_date = jdatetime.datetime.fromgregorian(datetime=dt_object_tehran)

    print(f"\nPost #{post_num})
    print(f"Date and Time: {jalali_date.strftime('%Y-%m-%d %H:%M:%S')}, Likes: {media.like_count}, Comments: {media.comment_count}")
    if media.media_type == 2:  # Video type
        print(f"Video Views: {media.view_count}")
    post_num -= 1  # Decrement the post number

if name == "main": cl = Client() cl.login("username", "password") usernames = ["pageid"] for username in usernames: get_instagram_data(username, cl) time.sleep(10) # Wait for 10 seconds between requests to avoid rate limits

ironhost avatar Oct 18 '23 07:10 ironhost

Hello,

I've been using your library and attempted to utilize the play_count attribute for media. However, even when a media should presumably have a play count, I'm consistently receiving a result of None.

Here's a brief snippet of my code:

python Copy code

media = cl.media_info_v1(media_id)
print(media.play_count)  # This prints "None" even for videos.

Based on the library's source code, I noticed that play_count is defined as Optional[int], which suggests it might be None. However, I'd expect this value to be populated for videos.

Can you provide some insight into this or let me know if there's something I might be missing?

Thank you!

ironhost avatar Oct 18 '23 07:10 ironhost

Hi, I am having the same issue!

Krishpandya682 avatar Dec 26 '23 02:12 Krishpandya682

Hi, User this | user_medias_v1(user_id: str, amount: int = 18) | List[Media] | Get a user's media by Private Mobile API

deepak-loqo avatar Apr 18 '24 20:04 deepak-loqo