0

我想讓我/我的家時間表,這是工作正常,但我也想要所有喜​​歡每個飼料,但它不工作。我通過調用函數的時間表,這樣我就可以調用同一個函數我的時間表或最後一個動作ID FB上做,等獲取臉譜喜歡計數與飼料

這是函數:

getRecentPosts('/me/home','feeds6'); 

當我把這個:

getRecentPosts('/me/home?fields=likes.limit(1).summary(1)','feeds6'); 

它給我未定義。
我嘗試調用它像這樣:

response.data[x].total_count 

我也試過likes.summary.total_countsummary.total_count。我究竟做錯了什麼?

+0

如果你想餵你爲什麼要查詢'/ me/home'而不是'/ me/feed'? –

+0

是啊好吧也許我解釋它錯了我換我想要我的時間線與喜歡 –

+0

顯然總數可以得到,但你的問題不清楚不是我 –

回答

0

的結果將是格式 -

{ 
    "data": [ 
    { 
     "id": "1111111111_2222222222", 
     "created_time": "2014-03-27T19:33:21+0000", 
     "likes": { 
     "data": [ 
      { 
       "id": "123456789564", 
       "name": "XXXXXX YYYYYY" 
      } 
     ], 
     "paging": { 
      "cursors": { 
       "after": "MTAwMDAwNDA0NDE2NTg2", 
       "before": "MTAwMDAwNDA0NDE2NTg2" 
      }, 
      "next": "https://graph.facebook.com/123213123213_1231234434/likes?limit=1&summary=1&after=MTAwMDAwNDA0NDE2NTg2" 
     }, 
     "summary": { 
      "total_count": 113 
     } 
    } 
    ] 
} 

因此,要獲取總計數,你應該試戴

if(response.data[x].summary !== undefined && response[x].data[x].summary.total_count !== undefined){ 
    count = response[x].data[x].summary.total_count; 
} 
else{ 
    count = 0; 
} 

也嘗試登錄完整response對象,以查看其內容。

+0

然後我在chrome中得到這個錯誤信息Uncaught TypeError:無法讀取all.js中未定義的屬性'total_count' –

+0

這是因爲您不會爲所有帖子獲取此「摘要」。請檢查您會在某處找到的帖子的完整列表。你還記錄了完整的「響應」嗎? –

+0

也許愚蠢的問題,但你究竟是什麼意思。 –