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.
2
Answers
Official documentation says URL should be a public one
So google search brought me here and I have a good answer for this but I assume that the OP doesn’t use StackOverflow anymore as this question is years old. However for anyone else running into this issue you can use ngrok for this.
Download and install ngrok. (If you are on windows and you download ngrok just have the exe in the same directory. If you are using linux download and install ngrok from your repo using apt-get, or yum, or snap depending on your linux flavor)
Run http server and ngrok then your pictures will be servable to instagram.
Instagram will take the url and get the picture.
Once its done immediately close the http and ngrok server.
Here is a python example that worked for me perfectly. You MUST have ngrok installed and you MUST get your api key (user token or app token……I hate meta’s token stuff. It took forever for me to understand. lol).
Remember to replace test.jpg with your actual photo.