subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.38k stars 686 forks source link

hashtag_medias_recent() returning 0 posts but no errors [BUG] #772

Closed trevtravtrev closed 2 years ago

trevtravtrev commented 2 years ago

Describe the bug hashtag_medias_recent() is returning zero posts with no error traceback. Its similar counterpart hashtag_medias_top() is working just fine.

To Reproduce

import instagrapi
import os

def login(username, password, session=True):
    session_path = "session.json"
    client = instagrapi.Client()
    if session:
        if session_path in os.listdir():
            client.load_settings(session_path)
    client.login(username, password)
    if session:
        client.dump_settings(session_path)
    return client

class EmailBot:
    def __init__(self, client):
        self.client = client
        self.amount = None
        self.hashtag = None
        self.type = None
        self.followers_username = None
        self.following_username = None

    def get_emails_from_hashtag(self, hashtag, amount, sort):
        self.hashtag = hashtag
        emails = []
        if sort == "top":
            posts = self.client.hashtag_medias_top(self.hashtag, amount=amount)
        elif sort == "recent":
            posts = self.client.hashtag_medias_recent(self.hashtag, amount=amount)
        else:
            raise Exception('Invalid type. Try "top" or "recent".')
        for post in posts:
            user = self.client.user_info_by_username(post.user.username)
            email = user.public_email
            if email:
                print(email)
                emails.append(email)
        return emails

    def get_emails_from_followers(self, followers_username):
        self.followers_username = followers_username

    def get_emails_from_following(self, following_username):
        self.following_username = following_username

def main():
    client = login("user1", "pass1", session=True)
    email_bot = EmailBot(client)
    emails = email_bot.get_emails_from_hashtag(hashtag='foryou', amount=500, sort="recent")
    print(emails)

if __name__ == '__main__':
    main()

Traceback There is no error message, it just grabs 0 posts.

Expected behavior It should be grabbing the amount of posts specified. It is grabbing 0 with no error.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

trevtravtrev commented 2 years ago

It seems to stem from the hashtag string I am searching. Some popular hashtags that return results with hashtag_medias_top(), return 0 results with hashtag_medias_recent(). This might not be a bug in the codebase but instagram not returning results for some reason. Interested to hear some thoughts.

adw0rd commented 2 years ago

try self.client.hashtag_medias_recent_v1(self.hashtag, amount=amount)