This guide explains how to comment on a Facebook Page post or comment on a Facebook Page post and @mention or tag a specific person or Page who has published a post on your Page or commented on a Page post using the Pages API from Meta.
This guide assumes you have read the Overview and the Posts guide for the Facebook Pages API.
For a person who can perform tasks on the page, you will need to implement Facebook Login on your app to ask for the following permissions and receive a Page access token:
pages_manage_engagement
pages_read_engagement
pages_read_user_engagement
Your app user must be able to perform the following tasks on the in the API requests:
MODERATE
CREATE_CONTENT
Your app will need the following features:
Khi thử nghiệm một lệnh gọi API, bạn có thể thêm thông số access_token
và đặt thông số này là mã truy cập của mình. Tuy nhiên, khi thực hiện lệnh gọi bảo mật từ ứng dụng của bạn, hãy sử dụng lớp mã truy cập.
You can comment on a Page post or a comment on a comment. The author of the comment will be the Page.
1705
error code with "message":"(#1705) There was an error posting to this wall"
.To comment on a Page post, send a POST
request to the /page_post_id/comments
endpoint with the message
parameter set to the content for your comment.
curl -i -X POST "https://graph.facebook.comv21.0
/page_post_id/comments" \
-H "Content-Type: application/json" \
-d '{
"message":"your_message_text",
}'
On success, your app receives the following JSON response with id
set to the comment ID:
{ "id":"comment_id" }
To comment on a comment, you will need to get the comments for a Page post, then get the ID for the comment you want to comment on.
To get the comments for a Page post, send a GET
request to the /page_post_id/comments
endpoint with the fields
parameter set to a comma-separated list that includes the message
field, to get the content for the comment and the from
field, to get the Page-scoped ID (PSID) for the person or Page who commented on the post, if you would like to @mention the person or Page in the comment.
curl -i -X GET "https://graph.facebook.com/page_post_id/comments?fields=from,message"
On success, your app receives the following JSON response with the commentor's name, PSID, message and the comment ID:
{ "data": [ { "created_time": "2020-02-19T23:05:53+0000", "from": { "name": "commentor_name", "id": "commentor_PSID" }, "message": "comment_content", "id": "comment_id" } ], "paging": { "cursors": { "before": "MQZDZD", "after": "MQZDZD" } } }
You can reply to a specific person or Facebook Page by mentioning, or tagging, the person in a comment. A notification will be sent to the person who has been mentioned by the Page. The most common uses for @mentions are:
When testing your app before going live, you must be an admin or a developer of the app and use Pages (both to make the API call, and to be used in a mention) for which you are an admin.
To mention a person or a Page who published a post on your Facebook Page, send a POST
request to the ID for the Page post with the message
parameter set to your comment content that includes the @
symbol with the person's PSID or the Page's ID.
curl -i -X POST "https://graph.facebook.comv21.0
/page_post_id" \
-H "Content-Type: application/json" \
-d '{
"message":"your_message_text @[PSID]",
}'
On success, your app receives the following JSON response with id
set to the ID for your comment:
{ "id":"comment_id" }
To mention a person or a Page who commented on your Facebook Page post, send a POST
request to the ID for the comment with the message
parameter set to your comment content that includes the @
symbol followed by an an array with the person's PSID or the Page's ID.
To mention multiple people, use an array of a comma-separated of PSIDs.
curl -i -X POST "https://graph.facebook.comv21.0
/comment_id" \
-H "Content-Type: application/json" \
-d '{
"message":"your_message_text @[PSID,PSID,PSID]",
}'
On success, your app receives the following JSON response with id
set to the ID for your comment:
{ "id":"comment_id" }
Learn how to start conversations with people who are interested in your Page and how to send a private reply to a specific person who has posted or commmented on your Page.