Search code examples
pythoncronbotsinstagramscheduler

I am looking for a tool that allows me to post to Instagram from python


I am looking for a tool that allows me to post to Instagram from python.

I would like to automate the process using a scheduler like Heroku or GCP cloud scheduler, so we think that something like selenium that uses GUI is not really suitable. (It may be possible to run it with selenium, though.)

I already tried instapy-cli and instabot, but they seemed to be unavailable now.

https://github.com/b3nab/instapy-cli

https://instagrambot.github.io/


Solution

  • You can try this code from Automating Instagram Posts with Python and Instagram Graph API.

    import requests
    import config
    import json
    
    def postInstagramQuote():
    #Post the Image
        image_location_1 = 'http:path-to-your-image.com/img/image-name.jpg'
        post_url = 'https://graph.facebook.com/v10.0/{}/media'.format(config.ig_user_id)
    payload = {
        'image_url': image_location_1,
        'caption': 'Get jobs online on https://careers-portal.co.za #career #hiring #jobs #job #jobssouthafrica #hiringnow,
        'access_token': config.user_access_token
        }
        r = requests.post(post_url, data=payload)
        print(r.text)
    result = json.loads(r.text)
        if 'id' in result:
            creation_id = result['id']
    second_url = 'https://graph.facebook.com/v10.0/{}/media_publish'.format(config.ig_user_id)
            second_payload = {
            'creation_id': creation_id,
            'access_token': config.user_access_token
            }
            r = requests.post(second_url, data=second_payload)
            print('--------Just posted to instagram--------')
            print(r.text)
        else:
            print('HOUSTON we have a problem')
    postInstagramQuote()
    

    REMINDER: You can only post from an Instagram business account, and not to your personal Instagram account.