本指南将说明如何以公共主页的身份创建、发布和更新帖子,回复在 Facebook 公共主页上发布的帖子,以及如何使用 Meta 的公共主页 API 删除帖子。
This guide assumes you have read the Overview
For a person who can perform tasks on the page, you will need to implement Facebook Login to ask for the following permissions and receive a Page access token:
pages_manage_engagementpages_manage_posts pages_read_engagement pages_read_user_engagement publish_video permission, if you are publishing a video to the PageYour app user must be able to perform the CREATE_CONTENT, MANAGE, and MODERATE tasks on the Page in the API requests.
If your app users do not own or manage the Page in the API requests, your app will need a User access token and the following features:
测试 API 调用时,您可以在调用中加入 access_token 参数,并将其设为您的访问口令。但是,从您的应用发出安全调用时,应使用访问口令类。
如要向公共主页发布帖子,请向 /page_id/feed 端点发送 POST 请求,其中 page_id 是您公共主页的编号,并在请求中加入以下参数:
message,设为您帖子的文本link,设为您的网址(如果您想发布链接)published,设为 true 可立即发布帖子(默认),设为 false 可之后发布
false,则加入 scheduled_publish_time,将日期设为以下其中一种格式:
1530432000)2018-09-01T10:15:30+01:00)
curl -X POST "https://graph.facebook.com/v25.0/page_id/feed" \
-H "Content-Type: application/json" \
-d '{
"message":"your_message_text",
"link":"your_url",
"published":"false",
"scheduled_publish_time":"unix_time_stamp_of_a_future_date",
}'若请求成功,您的应用会收到以下 JSON 响应,其中包含帖子编号:
{
"id": "page_post_id"
}
如要限制哪些用户可以查看公共主页帖子,您可以在 POST 请求中加入 targeting.geo_locations 对象或 feed_targeting.geo_locations 参数。
-d '{
...
"targeting": {
"geo_locations": {
"countries": [
"CA"
],
"cities": [
{
"key": "296875",
"name": "Toronto"
}
]
}
},
...
}'在某些情况下,同时使用国家/地区和该国家/地区内的区域会导致错误:“Some of your locations overlap.Try removing a location.”(您使用的一些位置重叠,请尝试删除。)在这些情况下,应根据您需要覆盖的范围定位区域或国家/地区。
您可以向公共主页发布照片和视频。
如要向公共主页发布照片,请向 /page_id/photos 端点发送 POST 请求,其中 page_id 是您公共主页的编号,并将 url 参数设为您帖子照片的路径。
curl -X POST "https://graph.facebook.com/v25.0/page_id/photos" \
-H "Content-Type: application/json" \
-d '{
"url":"path_to_photo",
若请求成功,您的应用会收到以下 JSON 响应,其中包含照片的编号和帖子的编号:
{
"id":"photo_id",
"post_id":"page_post_id"
}
如要获取公共主页帖子清单,请向 /{page-id}/feed 端点发送 GET 请求。
curl -i -X GET "https://graph.facebook.com/v25.0/page_id/feed"
若请求成功,您的应用会收到以下 JSON 响应,其中包含一个对象数组,该数组包含公共主页上每个帖子的帖子编号、帖子创建时间以及帖子内容:
{
"data": [
{
"created_time": "2019-01-02T18:31:28+0000",
"message": "This is my test post on my Page.",
"id": "page_post_id"
}
],
...
}
公共主页帖子的网址(或永久链接)为 https://www.facebook.com/page_post_id。
如要更新公共主页帖子,请向 /page_post_id 端点发送 POST 请求,并将要更新的参数设为新内容。
curl -X POST "https://graph.facebook.com/v25.0/page_post_id" \
-H "Content-Type: application/json" \
-d '{
"message":"I am updating my Page post",
}'
若请求成功,您的应用会收到以下 JSON 响应,其中 success 设为 true:
{
"success": true
}
应用只能更新使用该应用创建的公共主页帖子。
如要删除公共主页帖子,请向 /page_post_id 端点发送 DELETE 请求,其中 page_post_id 是您要删除的帖子的编号。
curl -i -X DELETE "https://graph.facebook.com/v25.0/page_post_id"
若请求成功,您的应用会收到以下 JSON 响应,其中 success 设为 true:
{
"success": true
}
了解如何在公共主页帖子中发表评论以及 @提及在您的公共主页上发布帖子或发表评论的特定用户或公共主页。