Versi Graph API

/{object-id}/likes

Referensi ini mendeskripsikan edge /likes yang umum untuk beberapa node Graph API. Struktur dan operasinya sama untuk setiap node. Objek berikut ini memiliki edge /likes:

Membaca

Memberikan daftar orang yang menyukai objek ini. Saat membaca suka di Halaman atau objek Pengguna, endpoint ini memberikan daftar halaman yang disukai oleh Halaman atau Pengguna itu.

Gunakan kolom likes dari objek untuk mendapatkan jumlah suka.

Kami rekomendasikan gunakan endpoint /object/reactions demi mendapatkan jumlah suka, jika tersedia.

Pengalaman Halaman Baru

Endpoint /likes objek berikut didukung untuk Pengalaman Halaman Baru:

  • Pengguna

Persyaratan

  • Persyaratan wajib yang sama untuk melihat objek diperlukan untuk melihat suka pada objek tersebut.

Batasan

  • Hanya jumlah agregat yang menggunakan total_count dengan parameter summary yang tersedia untuk suka Postingan.
  • Jumlah reaksi like termasuk reaksi "suka" dan "peduli".
  • total_count mewakili perkiraan jumlah suka, akan tetapi jumlah aktual hasil yang dikembalikan mungkin berbeda, bergantung pada pengaturan privasi.
  • Endpoint GET /{group-post-id}/likes dan GET /{post-id}/likes dihentikan di v8.0+ dan dihentikan di semua versi tanggal 2 Nov 2020.

Kolom

Nama Properti Deskripsi Jenis

total_count

Total jumlah suka Pengguna dan Halaman pada objek. Agar kolom ini dikembalikan, Anda harus menyertakan parameter dan nilai summary=true dalam permintaan Anda.

int32

Contoh Penggunaan

Contoh Permintaan
curl -i -X GET "https://graph.facebook.com/{object-id}
  ?fields=likes.summary(true)
  &access_token={access-token}"

Contoh Tanggapan

  {
  "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"
}

Menerbitkan

Sukai objek.

Pengalaman Halaman Baru

Endpoint /likes objek berikut didukung untuk Pengalaman Halaman Baru:

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
}];

Izin

  • Token akses Halaman yang diminta oleh orang yang dapat melakukan tugas CREATE_CONTENT di Halaman
  • Izin pages_manage_engagement

Batasan

  • Halaman juga harus dapat menyukai objek (baik melalui API atau di Facebook.com).
  • Objek tersebut harus belum disukai oleh Halaman.
  • Jika Halaman tersebut sudah menanggapi objek (wow, sedih) maka suka akan berhasil, tetapi tanggapan tersebut tidak akan berubah.
  • Menyukai ulasan Halaman tidak didukung.

Kolom

Tidak diperlukan adanya kolom untuk menambahkan suka.

Tanggapan

Setelah berhasil, aplikasi akan menerima tanggapan berikut:

{
  "success": true
}

Memperbarui

Anda tidak dapat melakukan operasi ini di endpoint ini.

Menghapus

Hapus suka pada objek Halaman menggunakan endpoint ini.

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
}];

Izin

  • Token akses Halaman yang diminta oleh orang yang dapat melakukan tugas MODERATE di Halaman
  • Izin pages_manage_engagement

Batasan

  • Pengguna atau Halaman hanya dapat menghapus likes-nya sendiri.
  • Objek tersebut harus sudah disukai.
  • Menghapus ulasan Halaman tidak didukung.

Kolom

Tidak ada kolom untuk endpoint ini.

Tanggapan

Setelah berhasil, aplikasi akan menerima tanggapan berikut:

{
  "success": true
}