php 通过 Facebook 图形 API 点赞帖子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4534975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Like posts over Facebook graph api
提问by simekadam
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).
你好!我对 facebook PHP SDK 没有什么问题。代码是,PHP SDK不知道这种POST请求(生成的链接肯定没问题)。我在 Facebook 开发人员页面上看到的内容大致相同..有一个 Curl 命令示例,我的 PHP SDK 正在通过 Curl 执行此请求(可能)。
$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).
$this->getFacebook()->api("/"+$id+"/likes", 'post');
这是我在我的代码中使用的,但它不起作用(Facebook API 异常不受支持的发布请求)。
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
)...
也许,我的代码中有错误的语法,但是,例如,当我想将状态发布到我的个人资料时,它正在工作..另一个让我感到困惑的原因是,当我试图通过 Graph api(在文档页面已写好,我应该使用像graph.facebook.com/POST_ID/likes
)这样的地址...
You can comment on or like a post by posting tohttps://graph.facebook.com/POST_ID/comments
andhttps://graph.facebook.com/POST_ID/likes
,respectively:
您可以在或喜欢一个帖子中发布评论https://graph.facebook.com/POST_ID/comments
和https://graph.facebook.com/POST_ID/likes
,分别为:
curl -F 'access_token=...' \
https://graph.facebook.com/313449204401/likes
<=this is from facebook documentation
curl -F 'access_token=...' \
https://graph.facebook.com/313449204401/likes
<=这是来自facebook文档
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.
所有这些请求或命令(喜欢的,我还没有尝试过的评论)让我回到一个 JSON 数组,其中包含任何已经存在的喜欢,但我的喜欢无处可去。
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:))
有谁知道该怎么做?如何喜欢来自 PHP 的帖子..还有其他像 FQL 这样的 SKD,但我对它一无所知,所以我更喜欢使用标准的 PHP SDK(但如果有一些可能性如何从 PHP SDK 调用例如 FQL,我在这里:))
Please help..
请帮忙..
采纳答案by ifaour
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:
好的,经过几次测试后,+
在发送参数时不要使用加号,因为单独的 ID 将作为参数发送给api
方法/
,/likes
因此使用:
$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.
还要确保您具有publish_stream
扩展权限,请参阅此文档。
回答by niels
View who likes object with id $id:
查看谁喜欢带有 id $id 的对象:
$this->getFacebook()->api("/$id/likes", 'get');
Add like to object with id $id:
将 like 添加到带有 id $id 的对象:
$this->getFacebook()->api("/$id/likes", 'post');
Remove like from object with id $id:
从 id 为 $id 的对象中删除 like:
$this->getFacebook()->api("/$id/likes", 'delete');
Make sure you have the publish_stream permission to post and delete likes.
确保您拥有发布和删除赞的 publish_stream 权限。
An easy wasy to experiment with this is through the facebook graphapi explorer.
一个简单的实验是通过 facebook graphapi explorer。
回答by Nathan Labenz
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/
Facebook 推出了一个 Graph API 浏览器,它可以帮助解决很多这些问题。它在这里:http: //developers.facebook.com/tools/explorer/
Quite handy!
很方便!