在PHP站點的頁面上添加Facebook評論插件的實例教程
首先,需要在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="http://connect.facebook.net/en_GB/all.js#xfbml=1&appId=這里填寫APPID"></script> <!-- comments plugins --> <fb:comments colorscheme="light" numposts="4" height="360px;" width="614px" fb-xfbml-state="rendered" class="fb_iframe_widget"></fb:comments>
在頁面上顯示如下

讀取頁面的分享總數(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); ?>
- PHP使用反射機(jī)制實現(xiàn)查找類和方法的所在位置
- PHP反射機(jī)制用法實例
- PHP中的reflection反射機(jī)制測試?yán)?/a>
- 實例介紹PHP的Reflection反射機(jī)制
- PHP 反射機(jī)制實現(xiàn)動態(tài)代理的代碼
- php利用反射實現(xiàn)插件機(jī)制的方法
- 在PHP中使用反射技術(shù)的架構(gòu)插件使用說明
- PHP框架Laravel插件Pagination實現(xiàn)自定義分頁
- Thinkphp和onethink實現(xiàn)微信支付插件
- PHP結(jié)合jQuery插件ajaxFileUpload實現(xiàn)異步上傳文件實例
- PHP基于反射機(jī)制實現(xiàn)插件的可插拔設(shè)計詳解
相關(guān)文章
php源碼之將圖片轉(zhuǎn)化為data/base64數(shù)據(jù)流實例詳解
在網(wǎng)站開發(fā)中,我們可以看到有的網(wǎng)站將圖片轉(zhuǎn)化為base64數(shù)據(jù)流,這樣做的好處有兩點,一是減少服務(wù)器http請求,二是可以將圖片作為字符串存儲在數(shù)據(jù)庫中,即圖片可以直接從數(shù)據(jù)庫中讀取,那么php如何將圖片轉(zhuǎn)化為data/base64字符串呢?,需要的朋友可以參考下2016-11-11
深入php函數(shù)file_get_contents超時處理的方法詳解
本篇文章是對php函數(shù)file_get_contents超時處理的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
基于thinkPHP實現(xiàn)的微信自定義分享功能示例
這篇文章主要介紹了基于thinkPHP實現(xiàn)的微信自定義分享功能,結(jié)合實例形式分析了thinkPHP調(diào)用微信接口實現(xiàn)自定義分享功能的相關(guān)操作技巧,需要的朋友可以參考下2016-09-09
php5 apache 2.2 webservice 創(chuàng)建與配置(java)
要運行wsCaller.jar 要選安裝jdk 如果沒有安裝jdk 則wsCaller.jar 會以壓縮包的形式顯示2011-01-01

