首先,需要在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。
?
1
|
2
3
4
5
|
<!-- 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 >
|
在页面上显示如下
读取页面的分享总数与评论总数
?
1
|
|
https://graph.facebook.com/?ids={YOUR_URL}
|
{YOUR_URL} 需要 urlencode
例如:https://graph.facebook.com/?ids=http%3A%2F%2Fwww.example.com%2F
返回:
?
1
|
2
3
4
5
6
7
|
{
" http://www.example.com/ ": {
"id": " http://www.example.com/ ",
"shares": 399517,
"comments": 392
}
}
|
代码如下:
?
1
|
2
3
4
5
6
7
8
|
<?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 );
?>
|
读取页面评论列表
?
1
|
|
https://graph.facebook.com/comments/?ids={YOUR_URL}
|
{YOUR_URL} 需要 urlencode
例如:https://graph.facebook.com/comments/?ids=http%3A%2F%2Fwww.example.com%2F
返回:
?
1
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
{
" 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再请求可以获取下一页的评论内容
代码如下:
?
1
|
2
3
4
5
6
7
8
|
<?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 );
?>
|
相关文章
猜你喜欢
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 47
-
2025-05-27 48
-
2025-05-25 91
-
2025-05-29 85
-
浅谈C++类型转化(运算符重载函数)和基本运算符重载(自增自减)
2025-05-27 67
热门评论