4

主要問題:不能得到「計數」

當我發出GET請求來檢索someID /職位的數據,如 https://graph.facebook.com/microsoft/posts?fields=comments,likes&limit=1&access_token=,使用由我自己的Facebook註冊應用程序生成的訪問令牌,無法在「likes」和「comments」字段中獲得「count」,但是如果使用來自Facebook的訪問令牌,則可以獲得預期數據。 「HelloFacebookSample」。

Android和FB Graph API Exploer都會出現此問題。另外爲了解決可能的原因,我使用了與我的註冊app_id下的FB樣本完全相同的代碼,但同樣的問題又出來了。所以我能想到的唯一可能的解釋是FB app_id的一些奇怪的事情,而不是權限範圍或不同的用戶(我已經使用兩個用戶測試過)。

這裏,在反應變量https://graph.facebook.com/microsoft/posts?fields=likes&limit=1&access_token= GET請求:

1.使用通過的access_token產生我APP_ID

{ 
    "data": [ 
    { 
     "id": "20528438720_10151574758413721", 
     "created_time": "2013-07-18T18:41:51+0000", 
     "likes": { 
      "data": [ 
      { 
       "id": "701134683", 
       "name": "Someone's name" 
      }, 
      { 
       "id": "113770258795376", 
       "name": "Someone's name" 
      } 
      /****and so on****/ 
     ], 
     "paging": { 
     "cursors": { 
      "after": "MTAwMDAwNjkxNDMxMTcz", 
      "before": "NzAxMTM0Njgz" 
     }, 
     "next": "https://graph.facebook.com/20528438720_10151574758413721/likes?limit=25&after=MTAwMDAwNjkxNDMxMTcz" 
     } 
    } 
    } 
    ], 
    "paging": { 
    "previous": "https://graph.facebook.com/20528438720/posts?fields=likes&limit=1&since=1374172911", 
    "next": "https://graph.facebook.com/20528438720/posts?fields=likes&limit=1&until=1374172910" 
    } 
} 

2,採用通過的access_token產生FB的樣品APP_ID (在這裏可以得到「贊」數):

{ 
    "data": [ 
     { 
     "likes": { 
      "data": [ 
      { 
       "name": "Someone's name", 
       "id": "100003531173993" 
      }, 
      { 
       "name": "Someone's name", 
       "id": "100002299390558" 
      }, 
      { 
       "name": "Someone's name", 
       "id": "1038509978" 
      }, 
      { 
       "name": "Someone's name", 
       "id": "1615491698" 
      } 
      ], 
     "count": 1071 
     }, 
     "id": "20528438720_10151574758413721", 
     "created_time": "2013-07-18T18:41:51+0000" 
    } 
    ], 
    "paging": { 
    "previous": "https://graph.facebook.com/20528438720/posts?fields=likes&limit=1&since=1374172911", 
    "next": "https://graph.facebook.com/20528438720/posts?fields=likes&limit=1&until=1374172910" 
    } 
} 

它真的讓我困惑了好幾天,而且我做了很多搜索,但找不到任何有用或相關的信息,可能是由於我的英文:P。還有其他人面臨類似的問題嗎?

謝謝您的閱讀。

任何幫助或替代解決方案讚賞! (在這裏,我只是想在我的應用中顯示喜歡的數量)

回答

7

剛剛找到解決方案,這一切都歸功於FB的遷移the October 2013 Breaking Changes。他們更改POST_ID/likes格式,但可能在遷移尚未完成的情況下發生,因此存在一些不一致之處。以下是我從Facebook Developer Alert獲得的官方聲明。

POST_ID /喜歡的格式會改變。應用程序將能夠通過分頁檢索所有喜歡的帖子(而不是現在的前4個)。作爲功​​能更新的結果,類似計數將被移至摘要字段

所以,現在,如果你不能看到「喜歡」,「數」或「備註」欄,只需按以下步驟操作:

  1. 發送GET請求,讓我們說https://graph.facebook.com/microsoft/posts?fields=likes&limit=1&access_token=,然後你會得到POST_ID =「id」
  2. 一個新的GET請求到https://graph.facebook.com/POST_ID/likes?summary=true&access_token=,那麼你會在「summary」字段中找到「likes」的「total_count」。

希望這會有所幫助!

+0

無論如何要做到這一點大塊?我曾經對'/?id = &fields = likes'執行一次API調用,但是添加了'&summary = true'來添加任何內容。 – Noam