在PHP站點的頁面上如何添加Facebook評論插件-創(chuàng)新互聯(lián)

這篇文章給大家分享的是有關(guān)在PHP站點的頁面上如何添加Facebook評論插件的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

創(chuàng)新互聯(lián)自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站制作、做網(wǎng)站網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元泌陽做網(wǎng)站,已為上家服務(wù),為泌陽各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220

首先,需要在facebook創(chuàng)建一個APP,創(chuàng)建方法見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。


<!-- include facebook js sdk --> 
<script id="facebook-jssdk" src="//connect.facebook.net/en_GB/all.js#xfbml=1&appId=這里填寫APPID"></script> 
 
<!-- comments plugins --> 
<fb:comments colorscheme="light" numposts="4" height="360px;" width="614px" href="http://www.example.com/" fb-xfbml-state="rendered" class="fb_iframe_widget"></fb:comments>

在頁面上顯示如下


在PHP站點的頁面上如何添加Facebook評論插件

讀取頁面的分享總數(shù)與評論總數(shù)


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" 
     } 
   } 
  } 
}

根據(jù)next的url再請求可以獲取下一頁的評論內(nèi)容

代碼如下:


<?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); 
?>

感謝各位的閱讀!關(guān)于“在PHP站點的頁面上如何添加Facebook評論插件”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

新聞標題:在PHP站點的頁面上如何添加Facebook評論插件-創(chuàng)新互聯(lián)
當前網(wǎng)址:http://muchs.cn/article28/cdchcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機、靜態(tài)網(wǎng)站網(wǎng)站設(shè)計公司、Google、網(wǎng)站建設(shè)、域名注冊

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營