Question

In the twitter search API you can use the unique id every search result has to reply to that post.

eg (php):

$twitter_json = file_get_contents("http://search.twitter.com/search.json?q=".$query."&lang=en", true);
$twitter_search_res = json_decode($twitter_json, true);
$id = $twitter_search_res['results'][0]['id'];
echo "<a href = 'https://twitter.com/intent/tweet?in_reply_to={$id}'>";

How can I reply to a post the Facebook graph search returns?

$fb_json = file_get_contents("http://graph.facebook.com/search?q=".$query."", true);
$fb_search_res = json_decode($fb_json, true);

With one of the results being:

array(7) {
  ["id"]=>
  string(31) "100000101152749_627923180554381"
  ["from"]=>
  array(2) {
    ["name"]=>
    string(19) "Jellie Artus Judith"
    ["id"]=>
    string(15) "100000101152749"
  }
  ["message"]=>
  string(101) "here comes the most awaited event of our lives. hahaha graduation of Wave95 (expedia)
:) pakaL time.."
  ["privacy"]=>
  array(1) {
    ["value"]=>
    string(0) ""
  }
  ["type"]=>
  string(6) "status"
  ["created_time"]=>
  string(24) "2013-04-18T19:18:23+0000"
  ["updated_time"]=>
  string(24) "2013-04-18T19:18:23+0000"
}

I tired using https://graph.facebook.com/{$fb_result_id}/comments but the id returned by the graph search doesn't seem to be the correct one. I also split the id at the '_' and neither of those worked.

Was it helpful?

Solution

As indicated on https://developers.facebook.com/docs/reference/api/search/, http://graph.facebook.com/search?q=YOUR_QUERY is search all public posts, this kind of posts most likely not the post from your friends, normally you doesn't have permissions to comments.

If you want to search the post from your news feed, you can do

https://graph.facebook.com/me/home?q=a&access_token=USER_ACCESS_TOKEN

Example comment by post_id using curl:

 <?php
    //extract data from the post
    extract($_POST);

    //set POST variables
    $url = 'https://graph.facebook.com/150552388343703_483757795023159/comments?access_token=USER_ACCESS_TOKEN';
    $msg = 'hello world testing';
    $fields = array(
                            'message' => urlencode($msg),
                    );

    //url-ify the data for the POST
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string, '&');

    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

    //execute post
    $result = curl_exec($ch);

    //close connection
    curl_close($ch);

    ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top