年紀大了有些事容易忘記... 所以.....

星期三, 5月 13, 2015

Facebook API 取得文章發文時間、分享數、留言數、按讚人數

Facebook API v2.3 適用

此篇透過 Facebook Graph 取得文章發文時間、分享數、留言數、按讚人數
不過以上資料都必需要連同 FB token 一起使用,文章 id 則是 AppId_文章id




※取得文章發文時間 & 分享數 (取created_time及shares下的count欄位)
範例:
https://graph.facebook.com/198059966970754_689786094464803?fields=created_time,shares&access_token=CAAXXXZAk0KQgBAP4USUOUcWJ7MngEik3iqjmdK9ChiypqecgeiQ4cGLcPz6O4fURAP5NnBvtsfXMf8nBZAIjSk4cZCLTj8tZAe5d7LwPDjHc6bXVta76iyBWloKFdZCdiEZCvSpA61I88AwyHS4XerOlkOLSNkocZC34tgLv6dhoZA8EHjFpc8nZBQ2bPaTPopaZA8sOlZAs68nQvCy9z1nJa2p

回傳內容:
{
   "created_time": "2015-03-28T15:08:49+0000",
   "shares": {
      "count": 7
   },
   "id": "198059966970754_689786094464803"
}


※取得文章留言數 (取summary下的total_count欄位)
範例:
https://graph.facebook.com/198059966970754_689786094464803/comments?summary=true&access_token=CAAXXXZAk0KQgBAP4USUOUcWJ7MngEik3iqjmdK9ChiypqecgeiQ4cGLcPz6O4fURAP5NnBvtsfXMf8nBZAIjSk4cZCLTj8tZAe5d7LwPDjHc6bXVta76iyBWloKFdZCdiEZCvSpA61I88AwyHS4XerOlkOLSNkocZC34tgLv6dhoZA8EHjFpc8nZBQ2bPaTPopaZA8sOlZAs68nQvCy9z1nJa2p

回傳內容:
{
   "data": [
      {
         "id": "689786094464803_689809567795789",
         "from": {
            "id": "10202906612344799",
            "name": "\u5f6d\u8304\u97cb"
         },
         "message": "\u73ed\u597d\u5e25 \u003C3",
         "can_remove": true,
         "created_time": "2015-03-28T16:15:13+0000",
         "like_count": 3,
         "user_likes": false
      }
   ],
   "paging": {
      "cursors": {
         "after": "WTI5dGJXVnVkRjlqZFhKemIzSTZOamc1T0RBNU5UWTNOemsxTnpnNU9qRTBNamMxTlRrek1UUT0=",
         "before": "WTI5dGJXVnVkRjlqZFhKemIzSTZOamc1T0RBNU5UWTNOemsxTnpnNU9qRTBNamMxTlRrek1UUT0="
      }
   },
   "summary": {
      "order": "chronological",
      "total_count": 1
   }
}


※取得文章按讚數 (取summary下的total_count欄位)
範例:
https://graph.facebook.com/198059966970754_689786094464803/likes?summary=true&access_token=CAAXXXZAk0KQgBAP4USUOUcWJ7MngEik3iqjmdK9ChiypqecgeiQ4cGLcPz6O4fURAP5NnBvtsfXMf8nBZAIjSk4cZCLTj8tZAe5d7LwPDjHc6bXVta76iyBWloKFdZCdiEZCvSpA61I88AwyHS4XerOlkOLSNkocZC34tgLv6dhoZA8EHjFpc8nZBQ2bPaTPopaZA8sOlZAs68nQvCy9z1nJa2p

回傳內容:
{
   "data": [
      {
         "id": "817290961683083",
         "name": "Sonsiri NuanKham"
      },
      {
         "id": "815877641834910",
         "name": "\u6842\u4eba\u845b"
      },
      {
         "id": "10205910121979431",
         "name": "Genny Shen"
      },
      {
         "id": "1002644486433585",
         "name": "Benz Sama"
      }
   ],
   "paging": {
      "cursors": {
         "after": "MTAwMjY0NDQ4NjQzMzU4NQ==",
         "before": "ODE3MjkwOTYxNjgzMDgz"
      }
   },
   "summary": {
      "total_count": 24
   }
}

延伸閱讀
https://developers.facebook.com/docs/graph-api/reference/v2.3/post
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/likes
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/comments