Summary
I have been trying to publish reels on Instagram using the Instagram API. However, none of my attempts have worked so far.
My setup
- I’m using an un-audited app on developers.facebook.com
- I want to publish on an instagram page I own (business account)
- This page was added to the app as an instagram tester
Documentation used
I have been following this page of the documentation on developers.facebook.com
My process
Step 1: OAuth
This part I did directly from the developer dashboard. The token I got has the following permissions:
- business_basic
- business_manage_messages
- business_content_publish
- business_manage_comments
Step 2: Create media container
For this part I’m doing just like the documentation says.
def create_instagram_media_container(ig_id: str, video_url: str, access_token: str):
url = f"https://graph.instagram.com/v20.0/{ig_id}/media"
headers = {
"Content-Type": "application/json",
}
data = {
"media_type": "REELS",
"video_url": video_url
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
return response.json()
else:
response.raise_for_status()
I am able to get a container ID with this step.
Note: After reading materials online, I have tried a few variations, including adding "Authorization": f"OAuth {access_token}"
to the header and "upload_type": "resumable"
to the data, but this didn’t fixed it.
Step 3: Publish container
Once again, I am following the documentation.
def upload_instagram_video(ig_id: str, ig_container_id: str, access_token: str):
url = f"https://graph.instagram.com/v20.0/{ig_id}/media_publish"
headers = {
"Content-Type": "application/json"
}
data = {
"creation_id": ig_container_id,
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
return response.json()
else:
response.raise_for_status()
At this stage however, I get an error.
At first I had the following description:
b'{"error":{"message":"Unsupported post request. Object with ID '[...]' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100,"error_subcode":33,"fbtrace_id":"AKe1_Gl1c5kNSTrKHPYuyHG"}}'
But now I just get a 400 error stating “Sorry, this content isn’t available right now”.
Note: After reading materials online, I have also tried adding "Authorization": f"OAuth {access_token}"
to the header here, but this didn’t fixed it.
My thoughts
I have a few ideas as to where the confusion could be comming from, but I didn’t really manage to make anything out of them.
- Endpoints: I am querying the
graph.instagram.com
endpoint, but there is also agraph.facebook.com
. This seemed a bit more complete, as the documentation mentions extra fields like caption, but I didn’t manage to make it work either. I think I should still go with the Instagram one as the documentation states that “Unlike the Instagram API with Facebook Login, this API doesn’t require a Facebook Page linked to the Instagram professional account.” which seems simpler. - Token: Reading online, I could see some mentions of a difference between a page token and a user token. I didn’t really understand the distinction. I generated my token directly from the “Instagram” tab of the developer website, and there is no such distinction there.
After trying for several days in a row, I am now completely lost. Your help would be greatly appreciated. Thank you!