เวอร์ชันของ API กราฟ

/{object-id}/likes

ข้อมูลอ้างอิงนี้จะอธิบายเกี่ยวกับจุดเชื่อมโยง /likes ซึ่งมักใช้กับโหนด API กราฟหลายรายการ โครงสร้างและการดำเนินการของแต่ละโหนดจะเป็นแบบเดียวกัน อ็อบเจ็กต์ต่อไปนี้มีจุดเชื่อมโยง /likes

การอ่าน

ส่งคืนรายชื่อผู้ที่กดถูกใจอ็อบเจ็กต์นี้ เมื่ออ่านจำนวนการกดถูกใจบนอ็อบเจ็กต์เพจหรือผู้ใช้ ตำแหน่งข้อมูลนี้จะส่งคืนรายชื่อเพจที่เพจหรือผู้ใช้นั้นๆ ได้กดถูกใจไว้

ใช้ช่อง likes ของอ็อบเจ็กต์เพื่อดึงข้อมูลจำนวนการกดถูกใจ

เราขอแนะนำให้คุณใช้ตำแหน่งข้อมูล /object/reactions เพื่อดึงข้อมูลจำนวนการกดถูกใจ (หากมี)

ประสบการณ์การใช้งานเพจแบบใหม่

ระบบรองรับตำแหน่งข้อมูล /likes ของอ็อบเจ็กต์ต่อไปนี้สำหรับประสบการณ์การใช้งานเพจแบบใหม่

  • ผู้ใช้

ข้อกำหนด

  • การดูจำนวนการกดถูกใจของอ็อบเจ็กต์จะใช้ข้อกำหนดแบบเดียวกันกับที่ต้องใช้ในการดูอ็อบเจ็กต์นั้น

ข้อจำกัด

  • จำนวนการกดถูกใจโพสต์จะมีเฉพาะจำนวนแบบผลรวมที่ใช้ total_count พร้อมพารามิเตอร์ summary
  • จำนวนความรู้สึก like จะรวมทั้งความรู้สึก "ถูกใจ" และ "ห่วงใย"
  • total_count แสดงถึงจำนวนการกดถูกใจโดยประมาณ แต่จำนวนแท้จริงที่ส่งคืนมาอาจต่างออกไปโดยขึ้นอยู่กับการตั้งค่าความเป็นส่วนตัว
  • เราเลิกใช้ตำแหน่งข้อมูล GET /{group-post-id}/likes และ GET /{post-id}/likes ในเวอร์ชั่น 8.0 ขึ้นไป และได้เลิกใช้ในทุกเวอร์ชั่นไปเมื่อวันที่ 2 พฤศจิกายน 2020

ช่อง

ชื่อคุณสมบัติ คำอธิบาย ประเภท

total_count

ผลรวมของจำนวนผู้ใช้และการกดถูกใจเพจบนอ็อบเจ็กต์ หากต้องให้ระบบส่งคืนช่องนี้ คุณจะต้องใส่พารามิเตอร์ summary=true และค่าไว้ในคำขอด้วย

int32

ตัวอย่างการใช้งาน

ตัวอย่างคำขอ
curl -i -X GET "https://graph.facebook.com/{object-id}
  ?fields=likes.summary(true)
  &access_token={access-token}"

ตัวอย่างการตอบกลับ

  {
  "likes": {
    "data": [
      {
        "name": "Bill the Cat",
        "id": "155111347875779",
        "created_time": "2017-06-18T18:21:04+0000"
      },
      {
        "name": "Calvin and Hobbes",
        "id": "257573197608192",
        "created_time": "2017-06-18T18:21:02+0000"
      },
      {
        "name": "Berkeley Breathed's Bloom County",
        "id": "108793262484769",
        "created_time": "2017-06-18T18:20:58+0000"
      }
    ],
    "paging": {
      "cursors": {
        "before": "Nzc0Njg0MTQ3OAZDZD",
        "after": "NTcxODc1ODk2NgZDZD"
      },
      "next": "https://graph.facebook.com/vX.X/me/likes?access_token=user-access-token&pretty=0&summary=true&limit=25&after=NTcxODc1ODk2NgZDZD"
    },
    "summary": {
      "total_count": 136
    }
  },
  "id": "user-id"
}

เผยแพร่

กดถูกใจอ็อบเจ็กต์

ประสบการณ์การใช้งานเพจแบบใหม่

ระบบรองรับตำแหน่งข้อมูล /likes ของอ็อบเจ็กต์ต่อไปนี้สำหรับประสบการณ์การใช้งานเพจแบบใหม่

POST /v19.0/{object-id}/likes HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post(
    '/{object-id}/likes',
    array (),
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
    "/{object-id}/likes",
    "POST",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{object-id}/likes",
    null,
    HttpMethod.POST,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{object-id}/likes"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

สิทธิ์การอนุญาต

  • โทเค็นการเข้าถึงเพจที่ขอโดยบุคคลที่สามารถดำเนินงาน CREATE_CONTENT บนเพจนั้นได้
  • สิทธิ์การอนุญาต pages_manage_engagement

ข้อจำกัด

  • เพจนั้นจะต้องสามารถกดถูกใจอ็อบเจ็กต์ได้เช่นกัน (ไม่ว่าจะผ่านทาง API หรือบน Facebook.com)
  • อ็อบเจ็กต์ดังกล่าวต้องยังไม่ได้รับการกดถูกใจโดยเพจนั้น
  • หากเพจนั้นได้แสดงความรู้สึกต่ออ็อบเจ็กต์แล้ว (ว้าว, เสียใจ) จะถือว่ากดถูกใจสำเร็จ แต่ความรู้สึกดังกล่าวจะไม่เปลี่ยนแปลงไป
  • ไม่รองรับการกดถูกใจการรีวิวเพจ

ช่อง

ไม่ต้องระบุฟิลด์เพื่อเพิ่มการกดถูกใจ

การตอบกลับ

เมื่อดำเนินการสำเร็จ แอพของคุณจะได้รับการตอบกลับดังต่อไปนี้

{
  "success": true
}

การอัพเดต

คุณไม่สามารถดำเนินการกับตำแหน่งข้อมูลนี้ได้

ลบ

ลบการกดถูกใจบนอ็อบเจ็กต์ในเพจโดยใช้ตำแหน่งข้อมูลนี้

DELETE /v19.0/{object-id}/likes HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->delete(
    '/{object-id}/likes',
    array (),
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
    "/{object-id}/likes",
    "DELETE",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{object-id}/likes",
    null,
    HttpMethod.DELETE,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{object-id}/likes"
                                      parameters:params
                                      HTTPMethod:@"DELETE"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

สิทธิ์การอนุญาต

  • โทเค็นการเข้าถึงเพจที่ขอโดยบุคคลที่สามารถดำเนินงาน MODERATE บนเพจนั้นได้
  • สิทธิ์การอนุญาต pages_manage_engagement

ข้อจำกัด

  • ผู้ใช้หรือเพจจะสามารถลบได้เพียง likes ของตนเองเท่านั้น
  • อ็อบเจ็กต์ต้องได้รับการกดถูกใจแล้ว
  • ไม่รองรับการลบการกดถูกใจการรีวิวเพจ

ช่อง

ไม่มีช่องสำหรับตำแหน่งข้อมูลนี้

การตอบกลับ

เมื่อดำเนินการสำเร็จ แอพของคุณจะได้รับการตอบกลับดังต่อไปนี้

{
  "success": true
}