Facebook Graph API - 删除喜欢

时间:2023-01-18
本文介绍了Facebook Graph API - 删除喜欢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 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模板网!

上一篇:Facebook 图形 API 仅返回某些网站的名称和 ID 下一篇:使用 Graph API PHP SDK 获取特定 Facebook 相册中的所有

相关文章

最新文章