在PHP站點(diǎn)的頁(yè)面上添加Facebook評(píng)論插件的實(shí)例教程
首先,需要在facebook創(chuàng)建一個(gè)APP,創(chuàng)建方法見(jiàn)https://developers.facebook.com/,APP有一項(xiàng)是填寫(xiě)Domain的,這里填寫(xiě)你website的Domain。(APP是綁定domain的,不能亂填)
然后就可以使用facebook comments plugins。
使用facebook comments plugins,可以在頁(yè)面中插入facebook comments。
生成code方法:https://developers.facebook.com/docs/plugins/comments
例如:有一個(gè)頁(yè)面是http://www.example.com/ ,在這個(gè)頁(yè)面中插入以下代碼便可以使用comments plugings。
<!-- include facebook js sdk --> <script id="facebook-jssdk" src="http://connect.facebook.net/en_GB/all.js#xfbml=1&appId=這里填寫(xiě)APPID"></script> <!-- comments plugins --> <fb:comments colorscheme="light" numposts="4" height="360px;" width="614px" fb-xfbml-state="rendered" class="fb_iframe_widget"></fb:comments>
在頁(yè)面上顯示如下

讀取頁(yè)面的分享總數(shù)與評(píng)論總數(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); ?>
讀取頁(yè)面評(píng)論列表
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再請(qǐng)求可以獲取下一頁(yè)的評(píng)論內(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ī)制實(shí)現(xiàn)查找類(lèi)和方法的所在位置
- PHP反射機(jī)制用法實(shí)例
- PHP中的reflection反射機(jī)制測(cè)試?yán)?/a>
- 實(shí)例介紹PHP的Reflection反射機(jī)制
- PHP 反射機(jī)制實(shí)現(xiàn)動(dòng)態(tài)代理的代碼
- php利用反射實(shí)現(xiàn)插件機(jī)制的方法
- 在PHP中使用反射技術(shù)的架構(gòu)插件使用說(shuō)明
- PHP框架Laravel插件Pagination實(shí)現(xiàn)自定義分頁(yè)
- Thinkphp和onethink實(shí)現(xiàn)微信支付插件
- PHP結(jié)合jQuery插件ajaxFileUpload實(shí)現(xiàn)異步上傳文件實(shí)例
- PHP基于反射機(jī)制實(shí)現(xiàn)插件的可插拔設(shè)計(jì)詳解
相關(guān)文章
Thinkphp集成抖音SDK的實(shí)現(xiàn)方法
這篇文章主要介紹了Thinkphp集成抖音SDK的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
Apache+php+mysql在windows下的安裝與配置(圖文)
2008-02-02
PHP SPL標(biāo)準(zhǔn)庫(kù)之SplFixedArray使用實(shí)例
這篇文章主要介紹了PHP SPL標(biāo)準(zhǔn)庫(kù)之SplFixedArray使用實(shí)例,SplFixedArray主要是處理數(shù)組相關(guān)的主要功能,它是固定長(zhǎng)度的,比普通的數(shù)組處理更快,需要的朋友可以參考下2015-05-05
在laravel中實(shí)現(xiàn)將查詢(xún)的對(duì)象轉(zhuǎn)換為多維數(shù)組的函數(shù)
今天小編就為大家分享一篇在laravel中實(shí)現(xiàn)將查詢(xún)的對(duì)象轉(zhuǎn)換為多維數(shù)組的函數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10
PHP命名空間(namespace)的使用基礎(chǔ)及示例
本文介紹了PHP命名空間的一些術(shù)語(yǔ),其解析規(guī)則,以及一些高級(jí)功能的應(yīng)用,希望能夠幫助讀者在項(xiàng)目中真正使用命名空間。2014-08-08
ThinkPHP實(shí)現(xiàn)圖片上傳操作的方法詳解
這篇文章主要介紹了ThinkPHP實(shí)現(xiàn)圖片上傳操作的方法,詳細(xì)分析了thinkPHP圖片上傳操作的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-05-05
Zend Framework教程之配置文件application.ini解析
這篇文章主要介紹了Zend Framework教程之配置文件application.ini用法,分析了配置文件application.ini中常見(jiàn)的配置項(xiàng)含義及用法,需要的朋友可以參考下2016-03-03

