Facebook Graph API - 删除点赞

发布于 2024-09-25 17:44:37 字数 287 浏览 5 评论 0原文

我正在用 PHP 为 Facebook 开发一个应用程序,其中一部分列出了用户的“喜欢”。我想在每个喜欢旁边添加一个链接,以便用户可以通过在他们认为合适的地方删除它们来管理他们的喜欢。

Facebook 在他们的 graph api 文档中提到了这一点:

您可以通过向 /POST_ID/likes 发出 DELETE 请求来删除点赞(因为点赞没有 ID)。

但每个点赞都必须有一个 id - 否则你怎么删除它呢?

以前有人这样做过吗?

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 mentions this in their graph api docs:

You can delete a like by issuing a DELETE request to /POST_ID/likes (since likes don't have an ID).

But each like must have an id - how else would you delete it?

Has anyone done this before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

惯饮孤独 2024-10-02 17:44:37

是的,点赞在 Graph API 中没有 ID。您可以通过 POST 或 DELETE 到 {item_id}/likes 来喜欢或不喜欢某个项目,其中 {item_id} 会替换为您喜欢/不喜欢的对象的 ID。

要找出当前用户喜欢的内容(以便您可以适当地删除它们),您可以使用 User 对象的“喜欢”连接(文档)。因此,如果您请求http://graph.facebook.com/me/likes,您将获得用户喜欢的页面/人员/任何内容的列表。 (注意:这不包括帖子或照片或类似的东西)

这将返回一个充满如下项目的数据数组:

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

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.

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

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.

生生漫 2024-10-02 17:44:37

具有 ID 的不是“喜欢”,而是帖子 - 这就是 api 调用使用“/POST_ID/likes”作为目标的原因 - 如果删除“/POST_ID”,它将删除该帖子,但是如果您删除“/POST_ID/likes”,它将删除用户对该帖子的“喜欢”。

It's not the 'like' that has an ID, it's the post - which is why the api call uses '/POST_ID/likes' as a target - if you delete '/POST_ID', it'll get rid of the post, but if you delete '/POST_ID/likes' it'll get rid of the user's 'like' for that post.

聊慰 2024-10-02 17:44:37

点赞确实有 ID。

如果您查看 https://graph.facebook.com/me/likes,您会看到结果数据确实包含每个的 ID 值。

{
   "data": [
      {
         "name": "Audi",
         "category": "Consumer_products",
         "id": "96585976469",
         "created_time": "2010-09-27T15:30:15+0000"
      }
    ]
}

您可能想尝试那里的 ID,我注意到 FB API 文档有时会出现错误。

编辑:我认为这也可能是一个术语问题,因为文档所说的没有 ID 的内容可能是对用户帖子的点赞,而这些可能实际上没有 ID,可以是通过向 POST_ID/likes 发出删除命令来删除。然后是通过点赞按钮点赞页面和/或外部网站生成的点赞,这些点赞都有一个 ID。确实令人困惑。

Likes do have an ID.

If you look at https://graph.facebook.com/me/likes, you will see that the resulting data does contain an ID value for each.

{
   "data": [
      {
         "name": "Audi",
         "category": "Consumer_products",
         "id": "96585976469",
         "created_time": "2010-09-27T15:30:15+0000"
      }
    ]
}

You might want to try the ID's there, I've noticed that the FB API doc sometimes has errors.

Edit: I think this also may be a terminology issue, as what the doc says doesn't have ID's is probably likes to a user post, and these probably don't really have an ID and can be removed by issuing a delete to the POST_ID/likes. Then there's the likes generated by liking pages and/or external websites via the like-button, and these DO have an ID. Confusing, it is.

愿得七秒忆 2024-10-02 17:44:37

对于 OpenGrpah,点赞确实有 id,它是对 og.likes 的 API 调用返回的对象中的单个 id 字段。

With OpenGrpah, likes do have ids, it is the single id field in the object returned by an API call to og.likes.

不忘初心 2024-10-02 17:44:37

不像使用access_token,它曾经使这

伪代码:

喜欢:

FacebookGraphApi::getInstance()->setAccessToken('xxx')->post('xxxxxx/likes')

不喜欢:

FacebookGraphApi::getInstance()->setAccessToken('xxx')->delete('xxxxx/likes')

You unlike using access_token which used to make this like.

Pseudocode:

to like:

FacebookGraphApi::getInstance()->setAccessToken('xxx')->post('xxxxxx/likes')

to unlike:

FacebookGraphApi::getInstance()->setAccessToken('xxx')->delete('xxxxx/likes')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文