Facebook Graph回复搜索结果

时间:2013-04-18 19:17:42

标签: php facebook-graph-api search reply

在Twitter搜索API中,您可以使用每个搜索结果必须回复该帖子的唯一ID。

例如(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}'>";

如何回复Facebook图表搜索返回的帖子?

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

结果之一是:

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"
}

我厌倦了使用https://graph.facebook.com/{$fb_result_id}/comments,但图搜索返回的ID似乎不正确。我也将id分配给'_',但这些都没有。

1 个答案:

答案 0 :(得分:0)

https://developers.facebook.com/docs/reference/api/search/所示, http://graph.facebook.com/search?q=YOUR_QUERY 是搜索所有公开帖子,此类帖子很可能不是您朋友的帖子,通常您没有权限评论。

如果您想从新闻Feed中搜索帖子,可以

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

使用curl的post_id示例注释:

 <?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);

    ?>