Like posts over Facebook graph api
Asked Answered
Q

3

9

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..

Quartersaw answered 26/12, 2010 at 18:47 Comment(0)
T
6

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.

Transmit answered 27/12, 2010 at 1:1 Comment(4)
Unfortunately, all of this returns to me only a list of currently existing likes..In particular some json object..Even if I wrote in my browser this address: graph.facebook.com/some_post_id/likes and even if I concatenated it with my access token (..?access_token=blabla) it din't work. And if I have this in my PHP code I am getting error: Fatal error: Uncaught OAuthException: (#100) The parameter url is required …it's trohwn on line 543 in facebook.php..Quartersaw
I'm 100% sure that your post_id structure is wrong, can you post that here?Transmit
ok this was one of the problem, the ID is wrong, try USERID_CURRENTID and tell me the results... this comment is helpfulTransmit
#12577981Toein
G
3

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.

Gorham answered 24/1, 2012 at 12:10 Comment(1)
#12577981Toein
H
2

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!

Harleyharli answered 7/8, 2011 at 2:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.