Instagram Graph Api Media Posts Between Dates
Solution 1:
Unfortunately the since
and until
parameters are not supported on this endpoint and this endpoint has only support cursor based pagination. The only way to do what I wish to do is to load each page of results individually using the before
and after
cursors provided in the API response.
Solution 2:
For your task, I would recommend you to not use InstagramAPI library. I will show you a simple solution for this using instabot library. For pip installation of this library, use this command:
pip install instabot
Use the following python code to get the media within the specified date range.
import datetime
from instabot import Bot
bot = Bot()
bot.login(username="YOUR USERNAME", password="YOUR PASSWORD")
defget_media_posts(start_date, end_date):
all_posts = bot.get_your_medias()
filtered_posts = []
for post in all_posts:
post_info = bot.get_media_info(post) #the media info for the post
post_timestamp = post_info[0].get('taken_at') #get the timestamp of the post
post_date = datetime.datetime.fromtimestamp(post_timestamp).date() #convert timestamp to dateif post_date >= start_date and post_date <= end_date:
filtered_posts.append(post) #or you can also use: filtered_posts.append(post_info)return filtered_posts
This will return you a list of all the posts within the specified date and you can use the bot.get_media_info(post)
to see what is inside every post.
NOTE: start_date and end_date should be in date() (and not in datetime) format according to this code but you can compare with whatever datetime function you want :)
Post a Comment for "Instagram Graph Api Media Posts Between Dates"