2011-12-15 117 views
1

通過使用圖表Facebook API我試圖找到與特定關鍵字相關的所有公共內容。如何使用Facebook社交圖譜API搜索查找評論數量和評論列表?

https://graph.facebook.com/search?q=obama&type=post 

我得到的結果如我所料,但最近我也想找到的寶貴意見及具體結果個體意見的列表中的號碼。

這是上面的API調用的輸出示例:

{ 
    "id": "1372608125_2297171713409", 
    "from": { 
     "name": "xxxx", 
     "id": "1372608125" 
    }, 
    "message": "Originaly posted by:Anthony McMahan\n\n Political breakdown time....\n \nToday is short one, here is some information that will floor you if you werent aware of it yet. The United States of America makes approximately 15 trillion dollars annually GDP. Our debt has recently tipped over 15 trillion in recent days. So we now owe more than we make in a year. \n\nTo further add to the fury, medical facilities in the USA account for 1/6 of our GDP, so about 2.5 trillion dollars are brought in from hospitals across the US. the new healthcare bill is a stretch for the givernment to take control of all medical facilities in the US, which would basically cancel out 1/6 of our income as the healthcare would be made available to everyone. Therefore in light of the US being in more debt than we could make in a year, the plan is to take away 1/6 of our ability to make money. Imagine being in credit card debt and having to take a pay cut at work, because you chose to work in the mailroom instead of a cubicle. thats what is going on here in allegory. i would just like to take this time to say, \"thank you mr obama for making this country a laughing stock in the eyes of all our enemies and foreign nations, you'd make Karl Marx and Vladimir Lenin all too proud.\" \n\nUntil tomorrow........", 
    "type": "status", 
    "created_time": "2011-12-15T06:02:51+0000", 
    "updated_time": "2011-12-15T06:02:51+0000" 
    } 

假設我要找到與該帖子的評論的評論的數量和名單。我應該使用另一個API調用嗎?
是否可以直接在「圖形API搜索」中直接瞭解註釋的數量,而無需調用其他API?我需要這個,所以如果一個帖子有評論,我會運行另一個API來獲取評論列表,否則我不需要運行額外的API調用。

據我所知獲得個人意見,我需要運行下面的API調用的列表:

http://graph.facebook.com/1372608125_2297171713409/comments 

是正確的方式來做到這一點?在這裏,我也沒有得到任何線索,無論這個職位是否真的有意見。

實際上,我希望得到類似的特徵,因爲Google+的API有地方中的一個搜索API調用,我可以得到的答覆(評論)的數量如下所示:

"replies": { 
"totalItems": 53, 
"selfLink": "https://www.googleapis.com/plus/v1/activities/z13rhfhjzzm4ztrnt22kwpgglsrjdfra504/comments" 
}, 

回答

0

是的,您需要爲每個帖子使用第二個API調用。

是否可以直接在'Graph API搜索'中直接瞭解註釋的數量,而無需調用其他API?我需要這個,所以如果一個帖子有評論,我會運行另一個API來獲取評論列表,否則我不需要運行額外的API調用。

常閱讀牆上或飼料時,您可以要求每個崗位,這將告訴你有多少評論有(試行/me/feed?fields=comments)的comments領域。無論出於何種原因,這似乎無法在搜索API中使用,並且請求評論字段會從API返回錯誤。

請求對帖子的評論正確的方法確實是:

http://graph.facebook.com/1372608125_2297171713409/comments 

如果你得到一個空列表背後,有沒有意見。否則,你會得到一個評論列表。你如何檢查這將取決於你使用的語言。對於沒有意見後,返回的原始JSON數據將是這個樣子:

{ 
    "data": [] 
} 

帖子上非常活躍的頁面可以有數千條評論,所以你可能要指定limit參數得到一堆同時意見,如果你打算打很多那些:

http://graph.facebook.com/1372608125_2297171713409/comments?limit=1000 

如果有不足千元的意見,你會得到他們都回來了與此一次。

0

您最好的選擇是最很可能讓你的代碼運行評論數量來獲得線程中的評論數量(如果有的話)。不幸的是,爲了做到這一點,你必須進行/ id/comments調用。我不知道有什麼方法可以通過額外的API調用來實現。

+0

該API調用返回的評論的數量?我試圖使用/ id/comments調用,但它給了我一個空的結果。這是否意味着該帖子沒有評論? – 2011-12-15 08:24:54

+0

是的。如果/ id/comments返回空結果,則該帖子爲空。您應該能夠使用您編碼的語言的函數來檢查此調用返回的結果數量。如果它說有0,那麼沒有任何評論。 – 2011-12-15 16:54:59

+0

謝謝。我仍在等待其他解決方案,這可以消除對沒有評論的帖子進行不必要的檢查。 – 2011-12-16 02:20:22

1

更簡單的方法是使用所謂的「批量請求」。它允許您一次執行多個Graph API請求,甚至可以讓您定義請求之間的依賴關係。完整的文檔可以找到here(您需要向下滾動一下「指定請求中操作之間的依賴關係」)。

您的第一個請求將是搜索結果,第二個請求將依賴於每個結果的圖形ID爲第一次調用的結果來獲取每個搜索結果的評論。

我還沒有與相關的批量請求的工作,但你應該給它一個嘗試:-)

相關問題