Comment Moderation

This guide shows you how to get comments, reply to comments, delete comments, hide/unhide comments, and disable/enable comments on Instagram Media owned by your app users using the Instagram Platform.

In this guide we will be using Instagram user and Instagram professional account interchangeably. An Instagram User object represents your app user's Instagram professional account.

Requirements

This guide assumes you have read the Instagram Platform Overview and implemented the needed components for using this API, such as a Meta login flow and a webhooks server to receive notifications.

You will need the following:

Instagram API with Instagram LoginInstagram API with Facebook Login

Access Tokens

  • Instagram User access token

Host URL

graph.instagram.com

graph.facebook.com

Login Type

Business Login for Instagram

Facebook Login for Business

Permissions
  • instagram_business_basic
  • instagram_business_manage_comments
  • instagram_basic
  • instagram_manage_comments
  • pages_read_engagement

If the app user was granted a role on the Page connected to your app user's Instagram professional account via the Business Manager, your app will also need:

  • ads_management
  • ads_read

Webhooks

  • comments
  • live_comments
  • comments
  • live_comments

Access Level

  • Advanced Access if your app serves Instagram professional accounts you don't own or manage
  • Standard Access if your app serves Instagram professional accounts you own or manage and have added to your app in the App Dashboard

Endpoints

Get comments

There are two ways to get comments on published Instagram media, an API query or a webhook notification. We strongly recommend using webhooks to prevent rate limiting.

API Request

To get all the comments on a published Instagram media object, send a GET request to the /<IG_MEDIA_ID>/comments endpoint.

curl -X GET "https://<HOST_URL>/v22.0/<IG_MEDIA_ID>/comments"

On success your app receives a JSON response with an array of objects containing the comment ID, the comment text, and the time the comment was published.

{
  "data": [
    {
      "timestamp": "2017-08-31T19:16:02+0000",
      "text": "This is awesome!",
      "id": "17870913679156914"
    },
    {
      "timestamp": "2017-08-31T19:16:02+0000",
      "text": "Amazing!",
      "id": "17870913679156914"
    },
		... // results truncated for brevity
  ]
}

Webhooks

When the comments or live_comments event is triggered your webhooks server receives a notification that include the ID for your app user's published media, the ID for the comments on that media, and the Instagram username for the person who published the comment.

Note: When hosting an Instagram Live story, make sure your server can handle the increased load of notifications triggered by live_comments webhooks events and that your system can differentiate between live_comments and comments notifications.

Facebook Login for Business

The following payload is returned for apps that have implemented Facebook Login for Business.

[
  {
    "object": "instagram",
    "entry": [
      {
        "id": "<YOUR_APP_USERS_INSTAGRAM_ACCOUNT_ID>",      // ID of your app user's Instagram professional account
        "time": <TIME_META_SENT_THIS_NOTIFICATION>          // Time Meta sent the notification
        "changes": [
          {
            "field": "comments",
            "value": {
              "from": {
                "id": "<INSTAGRAM_USER_SCOPED_ID>",         // Instagram-scoped ID of the Instagram user who made the comment
                "username": "<INSTAGRAM_USER_USERNAME>"     // Username of the Instagram user who made the comment
              }',
              "comment_id": "<COMMENT_ID>",                 // Comment ID of the comment with the mention
              "parent_id": "<PARENT_COMMENT_ID>",           // Parent comment ID, included if the comment was made on a comment
              "text": "<TEXT_ID>",                          // Comment text, included if comment included text
              "media": {                                       
                "id": "<MEDIA_ID>",                             // Media's ID that was commented on
                "ad_id": "<AD_ID>",                             // Ad's ID, included if the comment was on an ad post
                "ad_title": "<AD_TITLE_ID>",                    // Ad's title, included if the comment was on an ad post
                "original_media_id": "<ORIGINAL_MEDIA_ID>",     // Original media's ID, included if the comment was on an ad post
                "media_product_type": "<MEDIA_PRODUCT_ID>"      // Product ID, included if the comment was on a specific product in an ad
              }
            }
          }
        ]
      }
    ]
  }
]

Business Login for Instagram

The following payload is returned for apps that have implemented Business Login for Instagram.

[
  {
    "object": "instagram",
    "entry": [
      {
        "id": "<YOUR_APP_USERS_INSTAGRAM_ACCOUNT_ID>",
        "time": <TIME_META_SENT_THIS_NOTIFICATION>

    // Comment or live comment payload
        "field": "comments",
        "value": {
          "id": "<COMMENT_ID>",
          "from": {
            "id": "<INSTAGRAM_SCOPED_USER_ID>",
            "username": "<USERNAME>"
          },
          "text": "<COMMENT_TEXT>",
          "media": {
            "id": "<MEDIA_ID>",
            "media_product_type": "<MEDIA_PRODUCT_TYPE>"
          }
        }
      }
    ]
  }
]

Your app can parse the API or webhook notification for comments that match your app user's criteria then use the comment's ID to reply to that comment.

Reply to a comment

To reply to a comment, send a POST request to the /<IG_COMMENT_ID>/replies endpoint, where <IG_COMMENT_ID> is the ID for the comment which you want to reply, with the message parameter set to your message text.

Sample Request

curl -X POST "https://<HOST_URL>/v22.0/<IG_COMMENT_ID>/replies"
   -H "Content-Type: application/json" 
   -d '{
         "message":"Thanks for sharing!"
       }'

On success, your app receives a JSON response with the comment ID for your comment.

{
  "id": "17873440459141029"
}

If your app user has a lot of comments to reply to, you could batch the replies into a single request.

Next steps

Learn how to send a message to the person who commented on your app user's media post using Private Replies.