'How to get the most recent post from a user in python with instagrapi

docs(https://adw0rd.github.io/instagrapi/usage-guide/media.html)

Hey everyone, i have been working on a Instagram bot to automate my company's post. Though to get it to work i need to scan a users most recent post.

heres the code i have

from instagrapi import Client

def comments():

    insta_user = "username"
    insta_pass = "password"
    user_profile = "https://www.instagram.com/<user_name>/"
    api = Client() 
    api.login(insta_user, insta_pass) #logs in
    media_id = api.media_id(api.media_pk_from_url(<url of picture>))
    api.media_comment(media_id, user_comment_message)

as you can see we need the link of a users most recent post. ex:"https://www.instagram.com/p/xxxxxxxx/"

how would i go about getting that link with just a users pasge link?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source