在PHP網站的頁面上添加Facebook評論外掛程式的執行個體教程_php執行個體

來源:互聯網
上載者:User
首先,需要在facebook建立一個APP,建立方法見https://developers.facebook.com/,APP有一項是填寫Domain的,這裡填寫你website的Domain。(APP是綁定domain的,不能亂填)
然後就可以使用facebook comments plugins。

使用facebook comments plugins,可以在頁面中插入facebook comments。
產生code方法:https://developers.facebook.com/docs/plugins/comments

例如:有一個頁面是http://www.example.com/ ,在這個頁面中插入以下代碼便可以使用comments plugings。

     

在頁面上顯示如下

讀取頁面的分享總數與評論總數

https://graph.facebook.com/?ids={YOUR_URL} 

{YOUR_URL} 需要 urlencode
例如:https://graph.facebook.com/?ids=http%3A%2F%2Fwww.example.com%2F
返回:

{   "http://www.example.com/": {    "id": "http://www.example.com/",    "shares": 399517,    "comments": 392   } } 

代碼如下:

<?php $url = 'http://www.example.com/'; $api = 'https://graph.facebook.com/?ids=';  $result = json_decode(file_get_contents($api.urlencode($url)), true);  print_r($result); ?> 

讀取頁面評論列表

https://graph.facebook.com/comments/?ids={YOUR_URL} 

{YOUR_URL} 需要 urlencode
例如:https://graph.facebook.com/comments/?ids=http%3A%2F%2Fwww.example.com%2F
返回:

{   "http://www.example.com/": {    "comments": {      "data": [       {         "id": "395320319544_27462154",         "from": {          "id": "100000223906701",          "name": "Thu\u1eadn Phan Thanh"         },         "message": "hello moto",         "can_remove": false,         "created_time": "2013-10-07T10:01:40+0000",         "like_count": 1,         "user_likes": false       },       {         "id": "395320319544_27877980",         "from": {          "id": "100001638736612",          "name": "L\u00e3 Minh"         },         "message": "hi you",         "can_remove": false,         "created_time": "2013-11-13T02:57:01+0000",         "like_count": 4,         "user_likes": false       },       {         "id": "395320319544_27879381",         "from": {          "id": "100004229015145",          "name": "Th\u00f9y Dung"         },         "message": "Mg \u1ee7ng h\u1ed9 t\u1edb v\u1edbi nh\u1edb \u003C3",         "can_remove": false,         "created_time": "2013-11-13T05:38:12+0000",         "like_count": 3,         "user_likes": false       }       ...      ],      "paging": {       "cursors": {         "after": "MjU0",         "before": "Mzk4"       },       "next": "https://graph.facebook.com/v1.0/395320319544/comments?limit=25&after=MjU0"      }    }   } } 

根據next的url再請求可以擷取下一頁的評論內容

代碼如下:

<?php $url = 'http://www.example.com/'; $api = 'https://graph.facebook.com/comments/?ids=';  $result = json_decode(file_get_contents($api.urlencode($url)), true);  print_r($result); ?> 
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.