通过 Facebook 图 api 点赞帖子

发布于 2024-10-09 09:28:04 字数 993 浏览 2 评论 0原文

你好!我对 facebook PHP SDK 没有什么问题..我想通过 facebook PHP SDK 喜欢一个帖子或其他东西..我正在做这段代码,我认为它应该是正确的,但显然它不起作用..给定的错误代码是,PHP SDK不知道这种POST请求(生成的链接肯定没问题)。我在 Facebook 开发者页面上看到的内容大致相同。有一个 Curl 命令的示例,我的 PHP SDK 正在通过 Curl 执行此请求(可能)。

$this->getFacebook()->api("/"+$id+"/likes", 'post'); 这是我在代码中使用的,但它不起作用( Facebook API 异常不支持发布请求)。

也许,我的代码中的语法很糟糕,但是,例如,当我想将状态发布到我的个人资料时,它正在工作。另一个让我困惑的原因是当我尝试通过 Graph api 获取这些数据时(在文档页面已编写,我应该使用像 graph.facebook.com/POST_ID/likes 这样的地址)...

您可以通过发布到来评论或喜欢帖子 https://graph.facebook.com/POST_ID/comments https://graph.facebook.com/POST_ID/likes分别:

curl -F 'access_token=...' \ https://graph.facebook.com/313449204401/likes <=这是来自 facebook 文档

所有这些请求或命令(点赞、评论我还没有尝试过)都把我放回一个 JSON 数组内容任何已经存在的喜欢,但我的喜欢无处可去。

有人知道该怎么做吗?如何喜欢 PHP 的帖子..还有其他 SKD,例如 FQL,但我对此没有任何了解,所以我更喜欢使用标准 PHP SDK(但是否有可能)如何从 PHP SDK 调用例如 FQL,我在这里:))

请帮忙..

HI! I have little problem with facebook PHP SDK..I want to like a post, or something else via facebook PHP SDK..I am doing this code, I think it should be right, but  apparently it's not working..The given error code is, the PHP SDK dont know this kind of POST request(the generated link is definitely alright). What I have seen on Facebook Developers page is about the same..There is an example of Curl command, and I the PHP SDK is doing this requests over Curl (propably).

$this->getFacebook()->api("/"+$id+"/likes", 'post'); This is what I am using in my code and it's not working(Facebook API Exception unsupported post request).

Maybe, I have bad syntax in my code, but, for example, when I want to post a status to my Profile, it's working..Another cause which confused me, was when I tried to fetch these data over Graph api(on the documentation page is written, I should use address like graph.facebook.com/POST_ID/likes)...

You can comment on or like a post by posting to https://graph.facebook.com/POST_ID/comments and https://graph.facebook.com/POST_ID/likes,respectively:

curl -F 'access_token=...' \
https://graph.facebook.com/313449204401/likes
<=this is from facebook documentation

And all these requests or commands(liking ones, comments have I not yet tried) are putting me back a JSON array which contents any already existing likes, but my like is nowhere.

Does anyone know what to do?How to like a post from PHP..There are other SKDs like FQL, but I haven't any knowlegde with it, so I like rather to use the standard PHP SDK(but if is there some possibility how to call for example FQL from PHP SDK, here I am:))

Please help..

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

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

发布评论

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

评论(3

羁拥 2024-10-16 09:28:04

好的,经过几次测试后,在发送参数时不要使用加号 +,因为单独的 ID 将作为参数发送到没有 api 方法//likes 所以使用:

$this->getFacebook()->api("/".$id."/likes", 'post');

或者更好:

$this->getFacebook()->api("/$id/likes", 'post');

同时确保您拥有 publish_stream 扩展权限,请参阅此 文档

Okay, after a couple of tests don't use the plus sign + when sending the parameter as the ID alone will be send as argument to the api method without / and /likes so use:

$this->getFacebook()->api("/".$id."/likes", 'post');

Or even better:

$this->getFacebook()->api("/$id/likes", 'post');

Also make sure that you have the publish_stream extended permission, refer to this document.

烟花肆意 2024-10-16 09:28:04

查看谁喜欢 id 为 $id 的对象:

$this->getFacebook()->api("/$id/likes", 'get');

向 id 为 $id 的对象添加点赞:

$this->getFacebook()->api("/$id/likes", 'post');

从 id 为 $id 的对象中删除点赞:

$this->getFacebook()->api("/$id/likes", 'delete');

确保您拥有发布和删除点赞的publish_stream权限。

对此进行实验的一个简单方法是通过 facebook graphapi explorer

View who likes object with id $id:

$this->getFacebook()->api("/$id/likes", 'get');

Add like to object with id $id:

$this->getFacebook()->api("/$id/likes", 'post');

Remove like from object with id $id:

$this->getFacebook()->api("/$id/likes", 'delete');

Make sure you have the publish_stream permission to post and delete likes.

An easy wasy to experiment with this is through the facebook graphapi explorer.

殊姿 2024-10-16 09:28:04

Facebook 推出了 Graph API 浏览器,可以帮助解决许多此类问题。它在这里: http://developers.facebook.com/tools/explorer/

非常方便!

Facebook has introduced a Graph API explorer which can help resolve a lot of these issues. It is here: http://developers.facebook.com/tools/explorer/

Quite handy!

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