2013-04-18 32 views
0

在Twitter搜索API中,您可以使用每個搜索結果的唯一ID來回復該帖子。Facebook圖表回覆搜索結果

如(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分開,但這兩者都不起作用。

回答

0

由於上https://developers.facebook.com/docs/reference/api/search/指出,http://graph.facebook.com/search?q=YOUR_QUERY是搜索所有公開信息,這類職位很可能不會從你的朋友的帖子,通常你沒有權限評論。

如果你想要搜索的新聞源後,您可以使用curl做

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

例由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); 

    ?> 
+0

它的意思爲隨機搜索,我只是想知道是否有能力做同樣的事情Twitter允許 – iRector

+0

在你調用facebook搜索API後,你得到的數據,你提取「id」(或我們稱之爲POST_ID)字段,例如,150552388343703_483757795023159,然後你讓HTTP POS T請求https://graph.facebook.com/POST_ID/comments?access_token=USER_ACCESS_TOKEN,發佈數據爲「message = something」 –