「喜欢」使用 Facebook Graph API 的页面

发布于 2024-09-06 04:27:08 字数 257 浏览 4 评论 0原文

使用 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 技术交流群。

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

发布评论

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

评论(6

得不到的就毁灭 2024-09-13 04:27:08

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 集成的 Facebook 页面或网站
身份验证,开发者应继续使用 Like 按钮
社交插件。

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:

For Facebook Pages or websites that do not integrate with Facebook
Authentication, developers should continue to use the Like button
social plugin.

我乃一代侩神 2024-09-13 04:27:08

2016 年 6 月更新

仍然无法使用 Facebook API 为页面点赞,如 /{user_id}/likes 有关创建/更新/删除的文档页面

您无法在此端点上执行此操作。

在以前的版本中,消息更清晰(请参阅下面的引用),但结果是相同的:这是不可能的。

2014 年 5 月

/{user-id}/likes 文档页面介绍了 发布 Facebook 页面的点赞

您无法使用此边缘进行发布,因为无法通过任何 API 为 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:

You can't perform this operation on this endpoint.

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:

You can't publish using this edge, as it is not possible to like a Facebook Page via any API. You should use the Like Button if you want people to be able to like a page in your app.

This is the most obvious and clear statement that has been able to give me an answer to the question.

┊风居住的梦幻卍 2024-09-13 04:27:08

如果您的应用程序是开放图形应用程序,现在您可以喜欢使用 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/

秋千易 2024-09-13 04:27:08

如果您希望在 facebook 内的页面选项卡或画布页面中使用此功能(比如允许在喜欢的门控页面内点赞该页面),则可以采用 Tom Wells 在给 Luke 的回复中建议的解决方法。您首先在页面上嵌入其点赞按钮的 iframe 版本,然后只需在 JS 中监听 edge.create 事件,如下所示:

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked the URL: ' + response);
        // ...
    }
);

在回调中,您可以处理当用户喜欢该页面,比如离开喜欢的页面,或者显示仅喜欢的内容。

当用户单击类似 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:

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked the URL: ' + response);
        // ...
    }
);

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.

中性美 2024-09-13 04:27:08

我认为除了特定的合作伙伴网站(例如 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

生生不灭 2024-09-13 04:27:08

您可以使用 Facebook api 使用以下代码为对象及其对象 id 点赞

[FBRequestConnection startForPostWithGraphPath:[NSString stringWithFormat:@"/%@/likes",{object_id}] graphObject:nil completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
   //do you customisation post like here
}];

You can like an object with its object id using Facebook api using the following piece of code

[FBRequestConnection startForPostWithGraphPath:[NSString stringWithFormat:@"/%@/likes",{object_id}] graphObject:nil completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
   //do you customisation post like here
}];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文