《PHP应用:在PHP站点的页面上添加Facebook评论插件的实例教程》要点:
本文介绍了PHP应用:在PHP站点的页面上添加Facebook评论插件的实例教程,希望对您有用。如果有疑问,可以联系我们。
PHP学习首先,需要在facebook创建一个APP,创建办法见https://developers.facebook.com/,APP有一项是填写Domain的,这里填写你website的Domain.(APP是绑定domain的,不能乱填)
然后就可以使用facebook comments plugins.
PHP学习使用facebook comments plugins,可以在页面中插入facebook comments.
生成code办法:https://developers.facebook.com/docs/plugins/comments
PHP进修例如:有一个页面是http://www.example.com/ ,在这个页面中插入以下代码便可以使用comments plugings.
PHP进修
<!-- 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进修在页面上显示如下
PHP进修
PHP进修读取页面的分享总数与评论总数
PHP学习
https://graph.facebook.com/?ids={YOUR_URL}
PHP学习{YOUR_URL} 必要 urlencode
例如:https://graph.facebook.com/?ids=http%3A%2F%2Fwww.example.com%2F
返回:
PHP进修
{
"http://www.example.com/": {
"id": "http://www.example.com/",
"shares": 399517,
"comments": 392
}
}
PHP进修代码如下:
PHP进修
<?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);
?>
PHP进修读取页面评论列表
PHP学习
https://graph.facebook.com/comments/?ids={YOUR_URL}
PHP学习{YOUR_URL} 必要 urlencode
例如:https://graph.facebook.com/comments/?ids=http%3A%2F%2Fwww.example.com%2F
返回:
PHP学习
{
"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"
}
}
}
}
PHP学习根据next的url再哀求可以获取下一页的评论内容
PHP进修代码如下:
PHP进修
<?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应用:在PHP站点的页面上添加Facebook评论插件的实例教程》讨论,分享您的想法,维易PHP学院为您提供专业教程。
转载请注明本页网址:
http://www.vephp.com/jiaocheng/7768.html