Posting to Instagram, and its pitfalls

In a previous post, we showcased how we authenticate ourselves to our own social media profiles from our news pipeline. Of course, authentication is all well and good, but at the end of the day, we want to use that access to actually share some news with you.

In this blog post, we will be looking at one of the these services in detail, as it comes with a bit of a pitfall to watch out for, but first, let's take a look at all of them, to see what we actually share.

LinkedIn

On our LinkedIn page, we are focusing on headlines. Twice a day, we share the headlines of our top news, including a shortened teaser text to let you have a sneak peek at the full article. Given the mostly text-based nature of LinkedIn posts, the headlines by themselves are a natural fit for LinkedIn.

X

X, formerly Twitter, started with text-based content as well, but has since moved on to other forms of media. Nonetheless, our full headlines with teaser text is a bit long for a single tweet (are they still calling it that, or are they X's now?). Hence, we show a shortened caption with fitting hashtags on our X profile, and instead post a minute long video, with a narration of the top news layered on top. We will cover how that video comes into existence each time in another post.

Instagram

Lastly, Instagram. We actually post the same video as on X to Instagram Reels. While the content is the same, we however stumbled on a problem with posting to Instagram as we built the integration. This is, as mentioned before, what we will examine today.

For most social platforms, including X and LinkedIn, this is pretty straightforward. Once you have an access token, you call an endpoint in their API, and send over the content you would like to have shared. For Instagram… well, you sorta do that too, but there is more to it.

Firstly, all interactions with Instagram must go through Facebook's GraphQL API. If you have ever built an integration with Instagram, you likely stumbled upon this as well. From there, this is the call to make to push a video to Instagram Reels.


POST https://graph.facebook.com/${GRAPH_API_VERSION}/${INSTAGRAM_USER_ID}/media?media_type=REELS&video_url=${videoUrl}&caption=${encodedCaption}&share_to_feed=true&access_token=${accessToken}
                

You probably noticed that this required a video URL. In other words, your video must be posted as a public resource for Instagram to read. No such thing as posting data directly, unfortunately.

Looking past that, you may expect that this would be the end of the story. Call that endpoint, and watch your video on your timeline. Unfortunately, this is not the case. What you actually create here is what Instagram refers to as a “container”. This container is a shell that has a processing state. Phrased differently, this “starts the upload to Instagram”.

This makes this an asynchronous process, and Instagram expects you to act accordingly, by waiting. The expectation is that you regularly check the status of your container. There is no SLA as to when the container has finished processing, only a recommendation as to how long to wait: five minutes, with a check every minute. This check can be done with this call:


GET https://graph.facebook.com/${GRAPH_API_VERSION}/${containerId}?fields=status_code&access_token=${accessToken}
                

This results in a “status_code”, which can be multiple different values, most importantly “FINISHED”. Only if it has that value, your container is ready to be published.

You can probably imagine that you also have to take that step:


POST https://graph.facebook.com/${GRAPH_API_VERSION}/${INSTAGRAM_USER_ID}/media_publish?creation_id=${containerId}&access_token=${accessToken}
                

As you can see, this process splits up the basic act of posting content into multiple different steps, with one potentially failing to finish in time. Granted, this has only happened to us once. However, especially in comparison to other social media platforms, this seems rather complicated. If you are faced with programmatically sharing to Instagram, be sure to watch out for this “uniqueness”.