問題描述
我正在用 PHP 為 Facebook 開發一個應用程序,其中一部分列出了用戶的喜歡".我想在每個贊旁邊添加一個鏈接,以便用戶可以通過刪除他們認為合適的位置來管理他們的贊.
I'm developing an app for Facebook in PHP, part of which lists the user's "likes". I would like to add a link next to each like so that the user can manage their likes by deleting them where they see fit.
Facebook 在他們的圖形 API 文檔中提到了這一點:
Facebook mentions this in their graph api docs:
您可以通過向/POST_ID/likes 發出 DELETE 請求來刪除贊(因為贊沒有 ID).
You can delete a like by issuing a DELETE request to /POST_ID/likes (since likes don't have an ID).
但是每個贊都必須有一個 id——否則你會如何刪除它?
But each like must have an id - how else would you delete it?
以前有人這樣做過嗎?
推薦答案
是的,喜歡在 Graph API 中沒有 ID.您通過向 {item_id}/likes
發布或刪除來喜歡或不喜歡某個項目,其中 {item_id}
被您喜歡/不喜歡的對象的 ID 替換.
Yes, likes don't have an ID in the Graph API. You like or unlike an item by POSTing or DELETEing to {item_id}/likes
, where {item_id}
is replaced by the ID of the object you're liking/unliking.
要了解當前用戶喜歡什么(以便您可以適當地刪除它們),您可以使用用戶對象的喜歡"連接(文檔).因此,如果您請求 http://graph.facebook.com/me/likes
,您將獲得用戶喜歡的頁面/人員/任何內容的列表.(注意:這不包括帖子或照片或類似的東西)
To find out what the current user has liked (so you can delete them appropriately), you can use the "likes" connection of the User object (docs). So, if you request http://graph.facebook.com/me/likes
, you'll get a list of pages/people/whatever that a user has liked. (Note: this does not include posts or photos or things like that)
這將返回一個包含如下項目的數據數組:
This will return an array of data full of items like this:
{
"name": "Very Hungry Caterpillar",
"category": "Artist",
"id": "29956247793",
"created_time": "2009-03-27T15:48:29+0000"
}
里面的ID不是之類的ID.它是用戶點贊過的對象的 ID,所以要取消點贊,必須對 http://graph.facebook.com/29956247793/likes
進行 DELETE.
The ID in there is not the ID of the like. It is the ID of the object that the user has liked, so in order to un-like it, you have to make a DELETE to http://graph.facebook.com/29956247793/likes
.
這篇關于Facebook Graph API - 刪除喜歡的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!