instagrapi
instagrapi copied to clipboard
hashtag_medias_recent() returning 0 posts but no errors [BUG]
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):
- OS: Windows 11
- Python version 3.10.4
- instagrapi version 1.16.20
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.
try self.client.hashtag_medias_recent_v1(self.hashtag, amount=amount)