Skip to content

Latest commit

 

History

History

insta_reels_publishing_api_sample

Instagram Reels Publishing APIs

Required software

In order to run the sample app you will need to install some required software, as follows:

  • Node JS

You will need the following:

For simplicity, this sample guide assumes that you save every file at the root level of the app directory without any nested folder structures except for node modules.

Make sure the videos are in accordance with the guidelines below:

  • Container: MOV or MP4 (MPEG-4 Part 14), no edit lists, moov atom at the front of the file.
  • Audio codec: AAC, 48khz sample rate maximum, 1 or 2 channels (mono or stereo).
  • Video codec: HEVC or H264, progressive scan, closed GOP, 4:2:0 chroma subsampling.
  • Frame rate: 23-60 FPS.
  • Picture size:
  • Maximum columns (horizontal pixels): 1920
  • Required aspect ratio is between 0.01:1 and 10:1 but we recommend 9:16 to avoid cropping or blank spaces.
  • Video bitrate: VBR, 25Mbps maximum
  • Audio bitrate: 128kbps
  • Duration: 15 mins maximum, 3 seconds minimum
  • File size: 1GB maximum

Rate limit checks content_publishing_limit

Rate limit checks have been included in the sample app as of version 2.0.0. Instagram accounts are limited to 25 API-published posts within a 24 hour moving period. This limit is enforced on the POST /{ig-user-id}/media_publish endpoint when attempting to publish a media container. We recommend that your app also enforce the publishing rate limit, especially if your app allows app users to schedule posts to be published in the future.

Please refer to docs to learn more.

Custom Thumbnail Support thumb_offset

Custom Thumbnail support has been included in the sample app as of version 2.0.0. This parameter refers to the location, in milliseconds, of the video or reel frame to be used as the cover thumbnail image. The default value is 0, which is the first frame of the video or reel. For reels, If both cover_url and thumb_offset are specified, cover_url will used and thumb_offset will be ignored.

Cover URL cover_url

Cover URL support has been included in the sample app as of version 2.0.0. This is the path to an image to use as the cover image for the Reels tab. The image specified will be cURLed hence the image must be on a public server. If both cover_url and thumb_offset are specified, cover_url is used and thumb_offset will be ignored. The image must conform to the specifications for a Reels cover photo.

Location Tagging location_id

Location Tagging feature has been included in the sample app as of version 2.0.0. The location_id parameter refers to the ID of a Page associated with a location that you want to tag the reel with. Ensure to refer to pre-requisites required to search for Pages in the Before you start section of this README.

Carousel Posts

IG Content Publishing API now includes support for Carousel Posts. You may publish up to 10 images, videos, or a mix of the two in a single post (a carousel post). Publishing carousels is a three step process:

Carousel posts count as a single post against the account's rate limit.

Please note: This feature IS NOT included in the Sample App.

Example Video URLs for testing:

Best Practices

  • Always make sure that videos to be uploaded meet the supported video requirements
  • Upload and publish requests are asynchronous. This means that a success response is a simple acknowledgement from the server and does not necessarily guarantee that the video was uploaded successfully.
    • Make sure to implement a checking mechanism like polling to check the status of the video uploads. You can find one method implemented in the sample app by the name isUploadSuccessful.
    • You need to wait till the upload is successful before you can execute the /publish
    • An example of wait is shown in the isUploadSuccessful, which executes retries every 3 second, for a total of 90second wait period. If it exceeds that, it fails. You can handle this differently
  • There are different sets of errors in each request. Make sure to handle the errors properly.
  • Note that there are various ways of FB login. This sample app uses a sever-side solution. Make sure to browse all available options and choose the most optimal way for your implementation.

Running the project

Using a devcontainer

Note: Ensure that containers are enabled and supported by the version of Visual Studio Code that you are using.

  • Navigate to the corresponding subfolder: cd insta_reels_publishing_api_sample

  • Run npm install in your terminal

  • Create a new file called .env and copy/paste all the environment variables from .env.template. Replace any environnment variables that have placeholders, such as APP_ID.

  • Create an OpenSSL Cert

    • mkcert localhost - This will create a localhost pem file
    • You will see localhost.pem and localhost-key.pem files generated.
  • Running the Sample App

Locally

  • Install nodeJS, which you can get via Homebrew (MacOS only) - brew install node

  • Install mkcert to create the OpenSSL Certificate. If you're using Mac you can install it via Homebrew - brew install mkcert

  • Run npm install in your terminal

  • Create a new file called .env and copy/paste all the environment variables from .env.template. Replace any environnment variables that have placeholders, such as APP_ID.

  • Create an OpenSSL Cert using mkcert

    • To create an OpenSSL Cert for you local development environment, first, install mkcert if it's not already installed on your local machine using brew install mkcert
    • mkcert localhost - This will create a localhost pem file
    • You will see localhost.pem and localhost-key.pem files generated.
  • Running the Sample App

License

Reels Publishing APIs is Meta Platform Policy licensed, as found in the LICENSE file.