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_tok开发者_运维知识库en=...' \
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..
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.
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.
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!
精彩评论