「喜欢」使用 Facebook Graph API 的页面
使用 Graph API,我希望能够让授权用户“喜欢”某个页面。
我尝试发布以下内容
https://graph.facebook.com/${PAGE_ID}/likes?access_token=${ACCESS_TOKEN}
我收到 HTTP 错误 500 并伴有“无效的 post_id 参数” JSON 响应正文。看起来 /likes
资源适合喜欢墙贴而不是页面。我如何让它与页面一起使用?
Using the Graph API I'd like to be able to have an authorized user "like" a page.
I tried posting the following
https://graph.facebook.com/${PAGE_ID}/likes?access_token=${ACCESS_TOKEN}
And I get an HTTP error 500 accompanied by "Invalid post_id parameter" in the JSON response body. Looks like the /likes
resource is suited to liking a wall post and not a page. How do I get this to work with a page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Facebook 已宣布支持使用官方 内置功能对 Facebook 外部的 URL 进行点赞喜欢行动。您需要拥有
publish_actions
权限。该图的 url 是:https://graph.facebook.com/[User FB ID]/og.likes?object=OG_OBJECT_URL&access_token=USER_ACCESS_TOKEN
但是,您目前无法使用此功能来点赞 Facebook 上的页面,因为文档状态:
Facebook has announced support for liking URL's outside of Facebook by using the official built-in Like action. You need to have
publish_actions
permissions. The graph url for this is:https://graph.facebook.com/[User FB ID]/og.likes?object=OG_OBJECT_URL&access_token=USER_ACCESS_TOKEN
However, you cannot use this to like a page on Facebook currently, as the documentation states:
2016 年 6 月更新
仍然无法使用 Facebook API 为页面点赞,如
/{user_id}/likes
有关创建/更新/删除的文档页面:在以前的版本中,消息更清晰(请参阅下面的引用),但结果是相同的:这是不可能的。
2014 年 5 月
/{user-id}/likes
文档页面介绍了 发布 Facebook 页面的点赞:这是能够给我这个问题答案的最明显、最清晰的陈述。
Update June 2016
It's still not possible to like a page using Facebook API, as stated in the
/{user_id}/likes
documentation page about Creating/Updating/Deleting:In previous versions the message was clearer (see the quote below), but the result is the same: it's not possible.
May 2014
The
/{user-id}/likes
documentation page States about Publishing Likes of Facebook Pages:This is the most obvious and clear statement that has been able to give me an answer to the question.
如果您的应用程序是开放图形应用程序,现在您可以喜欢使用 api,而不再需要按钮。
https://developers.facebook.com/docs/opengraph/actions/builtin/喜欢/
if your app is an open graph app, now you can like using the api, and no need for the button anymore.
https://developers.facebook.com/docs/opengraph/actions/builtin/likes/
如果您希望在 facebook 内的页面选项卡或画布页面中使用此功能(比如允许在喜欢的门控页面内点赞该页面),则可以采用 Tom Wells 在给 Luke 的回复中建议的解决方法。您首先在页面上嵌入其点赞按钮的 iframe 版本,然后只需在 JS 中监听
edge.create
事件,如下所示:在回调中,您可以处理当用户喜欢该页面,比如离开喜欢的页面,或者显示仅喜欢的内容。
当用户单击类似 iFrame 的按钮时,假设 iFrame 已配置为指向相关页面的 url,您的 JS 代码应该会收到
edge.create
事件。If you want this functionality in a page tab or canvas page within facebook (say to allow for liking the page from within a likegated page), a work around you can involves what Tom Wells suggested in his reply to Luke. You first embed the iframe version of their like button on your page, and then simply listen for the
edge.create
event in your JS like so:In the callback, you can deal with with what happens when the user has liked the page, say like navigating away from the like-gate page, or showing liked-only content.
When the user clicks the iFrame like button, your JS code should receive the
edge.create
event assuming the iFrame was configured to point to the url of the page in question.我认为除了特定的合作伙伴网站(例如 yelp)之外,这是不允许的。原因是安全性,您可以在页面上放置一些 JavaScript,并让访问该页面的每个人在不知情的情况下“喜欢”它。
请参阅 Facebook 平台上的如何“喜欢”某个网址?开发者论坛
I believe this is not allowed except for specific partner sites, like yelp. The reason is security, you would be able to put some javascript on a page and have everyone that visits that page "Like"ing it without their knowledge.
See How do I "Like" a URL? on the Facebook Platform Developer Forum
您可以使用 Facebook api 使用以下代码为对象及其对象 id 点赞
You can like an object with its object id using Facebook api using the following piece of code