I continue to learn Facebook API [upd 09/25/2011]
This time I ran into comments.
Required: sending messages to the user's wall, followed by commenting.
')
Task: to give the opportunity to comment on the post to all Facebook users, not just friends.
And I will immediately disappoint:
today (09/21/2011) there is no human way to give access to commenting directly to everyone via Graph api.Those. there is a way of commenting, but by default commenting is allowed only for friends of the user whose record is located. If someone else is trying to leave a comment on your message, they will receive an error message with this content:
(#100) Error finding the requested story //
By the way, in order to comment, let's say posts on the wall of the application, you must first approve it by clicking on “I like”, in order to comment on the messages on the group wall, you need to join the group, etc.
On the other hand, if you install a comment plugin on the site and use it to send a message to the user's wall, then any visitor to this site will be able to comment on it (the message) (if he has already logged in on Facebook).
Remarkably, there is a way, it only remains to find out how everything works.
Only here is an ambush: in the documentation for the plugin only ryushki - tips on setting up the look (scant ones should be noted) and other unnecessary crap. There are no hints about how and where the data from the plugin is sent. But if you get wall entries through the API:
{ "data": [ { "id": "100001957292289_178950362180206", "from": { "name": "\u0410\u043d\u0442\u043e\u043d \u0413\u043e\u0440\u043e\u0434\u0435\u0446\u043a\u0438\u0439", "id": "100001957292289" }, "message": "Cats!", "actions": [ { "name": "Comment", "link": "http://www.facebook.com/100001957292289/posts/178950362180206" }, { "name": "Like", "link": "http://www.facebook.com/100001957292289/posts/178950362180206" } ], "privacy": { "description": "Friends of Friends", "value": "FRIENDS_OF_FRIENDS", "allow": "0", "deny": "0" }, "type": "status", "application": { "name": "pilot", "id": "174611799256077" }, "created_time": "2011-09-21T18:24:50+0000", "updated_time": "2011-09-21T18:24:50+0000", "comments": { "count": 0 } },
That no trace of the newly recorded record will not be there. And no wonder. Long-term studies show that wall posts are type: status, while wall posts sent from the comment plugin are type: link_stat.
After reading thoughtfully 70-80 on stackoverflow.com, in the most natural sense, I get an overflow of the stack of the brain and in anticipation of the deprivation of my mind I stumble upon this design:
graph.facebook.com/comments/?ids=http://example.org/post/35/
By that time, I had played enough with the experiments, so without departing from the cash register, I try this design in Facebook-explorere.
And lo and behold - I get the coveted JSON with information about this post.
By the way, if at the same address (https://graph.facebook.com/DIGITS_MOREDIGITS/comments) to make a post-request, then a new post will be sent:
graph.facebook.com/comments/?ids=http://nadvoe.org.ua/stud.my/post/35/
So, I send GET, I get the post id out of the returned json-object and try to send a comment on this id:
graph.facebook.com/DIGITS_MOREDIGITS/comments
To which I get a response from Facebook:
(#100) Invalid fbid. //
By the same way again complex mental frauds, I find out that the comments will freely go if everything is removed from the id from the bottom line:
graph.facebook.com/DIGITS _MOREDIGITS /comments
Comments will be sent to this address successfully, and from any users.
[upd 09/25/2011]
In the identifier DIGITS_MOREDIGITS, DIGITS is an identifier of an object of type type: website, together these characters make up the value of the id field from the comment table
Below are new conclusions about this.
Those. in principle, DIGITS_MOREDIGITS is the correct message identifier, but if you try to get comments on this address:
graph.facebook.com/DIGITS_MOREDIGITS/comments
facebook will return void in json format.
It would be logical to try to make an FQL query to the comment table, putting id = DIGITS_MOREDIGITS in the condition. But the id field in the comment table (no matter how strange and mysterious it is!) Is not indexed, which Facebook will kindly remind us of:
Your statement is not indexable. The WHERE clause must contain an indexable column. Such columns are marked with * in the tables
offtop: I send hate rays to facebook developers for not doing a column that should be canonically indexed.By the way, the identifier by which you can extract comments to a specific post is in the
post_fbid column (also, by the way, not indexable).
Thus, the subtask is reduced to identifying the correspondence between these identifiers. The truth is that we can only have the URL to which the comment plugin was attached. In this case, from the link_stat table (as mentioned above - this is just the type of those posts that are sent from the comments plug-in to the wall) we need to extract the object identifier (object_id) by url. And then by this identifier select all fbid_post and id. In general it is better to show the query (FQL):
SELECT post_fbid, id FROM comment WHERE object_id IN (SELECT comments_fbid FROM link_stat WHERE url ='".base_url()."')
Accordingly, I supplemented my facebook class extension with the function of receiving id_ for which you can get_ or send_comment on id_ who_returns_ after_the creation of post_through_plugin_ of comments:
public function getRealPostId($given_post_id) { $fql =" SELECT post_fbid, id FROM comment WHERE object_id IN (SELECT comments_fbid FROM link_stat WHERE url ='".base_url()."') "; $params = array( 'query' => $fql, 'method' => 'fql.query', 'callback' => '' ); $result = $this->api($params); foreach($result as $row) { if ($row['id']==$given_post_id) return $row['post_fbid']; } return false; }
[/ upd]
In principle, all this works wonderfully, but then I try to introduce it to my site, then I get another unpleasant surprise in the form of an error:
"Unknown identifier, "
Facebook complains that this identifier is not known to him. Searching the personal Facebook section on stackoverflow makes me think that each address must be initialized before it can be used.
This can be done in two ways (although essentially one):
- Run a comment plugin on your site
- View the source of the iframe plugin comments and pull this source "transparently" for the user and once for all new URLs on the site.
By the second method I decided the case (the extended facebook php sdk class was used, the function is written under codeigniter):
public function add() {
This is how you can ensure that anyone can comment on your posts on your facebook wall left through the app.