[Python] How to upload image saved in local device to Instagram Graph API

Discussão em 'Python' iniciado por Stack, Julho 19, 2025.

  1. Stack

    Stack Membro Participativo

    I want to post on Instagram using Facebook Graph API. To post image, it require URL of image saved in public server. Below is the python code which I am using -

    def postInstagram(): post_url = "https://graph.facebook.com/my_id/media"

    payload = {
    "image_url": image_url,
    "caption": my_caption,
    "access_token": my_token}
    r = requests.post(post_url, data=payload)

    result = json.loads(r.text)
    if 'id' in result:
    creation_id = result['id']

    second_url = "https://graph.facebook.com/v13.0/my_id/media_publish"
    second_payload = {
    "creation_id": creation_id,
    "access_token": "my_token"
    }
    r = requests.post(second_url, data=second_payload)


    But I want to post image directly by uploading it from my local device and not by URL. I don't know how to do that. Please help me.

    Continue reading...

Compartilhe esta Página