本指南說明如何建立、發佈及更新貼文,以及如何以粉絲專頁身分回覆 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 參數組合包含在存取權杖中。不過,從應用程式進行安全呼叫時,請使用存取權杖類別。
若要發佈貼文至粉絲專頁,請傳送 POST 要求至 /page_id/feed 端點(其中 page_id 為粉絲專頁編號),並使用下列參數:
message 設為貼文的文字link 設為您的網址(若要張貼連結)published 設為 true 以立即發佈貼文(預設),或設為 false 以稍後發佈
false,請包含 scheduled_publish_time,並使用下列任一日期格式:
15304320002018-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"
}
]
}
},
...
}'某些情況下,同時使用國家和該國家境內的地區會發生錯誤:「有部分地點重疊。請嘗試移除一個地點。」這時候,請依據您想要的覆蓋範圍,選擇目標地區或國家。
您可以發佈相片和影片至粉絲專頁。
若要發佈相片至粉絲專頁,請傳送 POST 要求至 /page_id/photos 端點(其中 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"
}
若要取得粉絲專頁貼文清單,請傳送 GET 要求至 /page_id/feed 端點。
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。
若要更新粉絲專頁貼文,請發送 POST 要求至 /page_post_id 端點,並將想要更新的參數設為新內容。
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
}
除非貼文是使用應用程式建立,否則該應用程式無法更新粉絲專頁貼文。
若要刪除粉絲專頁貼文,請傳送 DELETE 要求至 /page_post_id 端點,其中 page_post_id 是您想要刪除的貼文編號。
curl -i -X DELETE "https://graph.facebook.com/v25.0/page_post_id"
成功時,應用程式會收到下列 JSON 回應,其中 success 設為 true:
{
"success": true
}
深入瞭解如何在粉絲專頁貼文上發表評論以及 @提及在您的粉絲專頁上發佈或評論的特定用戶或粉絲專頁。