Instagram Management

Manage comments on Instagram using the Facebook Business SDK.

Requirements

Endpoints

  • The /comment node — delete and hide/unhide comments
  • The /commment/replies edge — send and receive comments
  • The /media node — disable/enable comments on a media object

Refer to each endpoint's reference documentation for parameter and permission requirements.

Get your Instagram Business Account ID

Before you can publish to Instagram, you need to get your Instagram Business Account ID.

Sample Code

$api = Api::init($app_id, null, $page_access_token_for_ig);
$fields = array(
  'instagram_business_account',
);
$params = array(
);
$page = (new Page(<PAGE_ID_FOR_IG>))->getSelf(
  $fields,
  $params
);
FacebookAdsApi.init(access_token=page_access_token_for_ig)
fields = [
    'instagram_business_account',
]
params = {
}
page = Page(<PAGE_ID_FOR_IG>).api_get(
    fields=fields,
    params=params,
)
context = new APIContext(page_access_token_for_ig).enableDebug(false);
Page page = new Page(<PAGE_ID_FOR_IG>, context).get()
  .requestInstagramBusinessAccountField()
  .execute();
FacebookAds::Session.default_session.access_token = page_access_token_for_ig
page = FacebookAds::Page.get(<PAGE_ID_FOR_IG> ,'instagram_business_account,').load!
bizSdk.FacebookAdsApi.init(page_access_token_for_ig);
fields = [
  'instagram_business_account',
];
params = {
};
let page = await (new Page(<PAGE_ID_FOR_IG>)).get(
  fields,
  params
);

Comment on an Instagram Business Account Posts

You can get comments on your media objects, analyze these comments, filter against specific criteria, then reply to any comments that match your criteria.

Step 1. Use the /media/comments edge to get all comments and their IDs.

Step 2. Select the comment to which you want to reply and use the comment ID to reply in the comment thread to the User.

Sample Code

$api = Api::init($app_id, null, $page_access_token_for_ig);
$fields = array(
);
$params = array(
);
$ig_comments = (new IGMedia(<IG_POST_ID>))->getComments(
  $fields,
  $params
);
$ig_comment_id = $ig_comments[0]->id;
$fields = array(
);
$params = array(
);
$ig_comment_repliess = (new IGComment($ig_comment_id))->getReplies(
  $fields,
  $params
);
FacebookAdsApi.init(access_token=page_access_token_for_ig)
fields = [
]
params = {
}
ig_comments = IGMedia(<IG_POST_ID>).get_comments(
    fields=fields,
    params=params,
)
ig_comment_id = ig_comments[0].get_id()
fields = [
]
params = {
}
ig_comment_repliess = IGComment(ig_comment_id).get_replies(
    fields=fields,
    params=params,
)
context = new APIContext(page_access_token_for_ig).enableDebug(false);
APINodeList<IGComment> igComments = new IGMedia(<IG_POST_ID>, context).getComments()
  .execute();
String ig_comment_id = igComments.get(0).getId();
IGComment igComment = new IGComment(ig_comment_id, context).get()
  .execute();
APINodeList<IGComment> igCommentRepliess = new IGComment(ig_comment_id, context).getReplies()
  .execute();
FacebookAds::Session.default_session.access_token = page_access_token_for_ig
i_g_media = FacebookAds::IgMedia.get(<IG_POST_ID>)
ig_comments = i_g_media.comments({
})
ig_comment_id = ig_comments[0].id
print 'ig_comment_id:', ig_comment_id
i_g_comment = FacebookAds::IgComment.get(ig_comment_id)
ig_comment_repliess = i_g_comment.replies({
})
bizSdk.FacebookAdsApi.init(page_access_token_for_ig);
fields = [
];
params = {
};
let ig_comments = await (new IGMedia(<IG_POST_ID>)).getComments(
  fields,
  params
);
let ig_comment_id = ig_comments[0].id;
fields = [
];
params = {
};
let ig_comment = await (new IGComment(ig_comment_id)).get(
  fields,
  params
);

fields = [
];
params = {
};
let ig_comment_repliess = await (new IGComment(ig_comment_id)).getReplies(
  fields,
  params
);

Learn More