本指南講解如何使用 Meta 專頁 API,以專頁身分在您的 Facebook 專頁上建立、發佈、更新、回應和刪除帖子。
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 設為有關網址
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"
}
]
}
},
...
}'在部分情況下,如果您同時鎖定國家或地區及當地的區域,便會導致以下錯誤:「你有部分地點重疊,請嘗試移除地點。」在這些情況下,請視您要涵蓋的範圍鎖定區域或國家。
您可以在專頁上發佈相片和影片。
如要在專頁上發佈相片,請向 /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 回應,其中包含設為 true 的 success:
{
"success": true
}
應用程式只能更新以其建立的專頁帖子。
如要刪除專頁帖子,請向 /page_post_id 端點傳送 DELETE 要求,其中 page_post_id 是您想刪除的帖子所屬編號。
curl -i -X DELETE "https://graph.facebook.com/v25.0/page_post_id"
成功的話,您的應用程式就會收到以下 JSON 回應,其中包含設為 true 的 success:
{
"success": true
}
了解如何回應專頁帖子和 @提及在您專頁上發佈內容或回應的特定用戶或專頁。