在PHP站点的页面上添加Facebook评论插件的实例教程
网络编程 2021-07-05 09:09www.168986.cn编程入门
这篇文章主要介绍了在PHP站点的页面上添加Facebook评论插件的实例教程,这样用户便可以以Facebook的用户身份在Facebook样式的评论表单上发表评论,需要的朋友可以参考下
首先,需要在facebook创建一个APP,创建方法见https://developers.facebook./,APP有一项是填写Domain的,这里填写你website的Domain。(APP是绑定domain的,不能乱填)
然后就可以使用facebook ments plugins。
使用facebook ments plugins,可以在页面中插入facebook ments。
生成code方法:https://developers.facebook./docs/plugins/ments
例如:有一个页面是http://.example./ ,在这个页面中插入以下代码便可以使用ments plugings。
<!-- include facebook js sdk --> <script id="facebook-jssdk" src="//connect.facebook./en_GB/all.js#xfbml=1&appId=这里填写APPID"></script> <!-- ments plugins --> <fb:ments colorscheme="light" numposts="4" height="360px;" width="614px" href="http://.example./" fb-xfbml-state="rendered" class="fb_iframe_widget"></fb:ments>
在页面上显示如下
读取页面的分享总数与评论总数
https://graph.facebook./?ids={YOUR_URL}
{YOUR_URL} 需要 urlencode
例如:https://graph.facebook./?ids=http%3A%2F%2F.example.%2F
返回:
{ "http://.example./": { "id": "http://.example./", "shares": 399517, "ments": 392 } }
代码如下:
<?php $url = 'http://.example./'; $api = 'https://graph.facebook./?ids='; $result = json_decode(file_get_contents($api.urlencode($url)), true); print_r($result); ?>
读取页面评论列表
https://graph.facebook./ments/?ids={YOUR_URL}
{YOUR_URL} 需要 urlencode
例如:https://graph.facebook./ments/?ids=http%3A%2F%2F.example.%2F
返回:
{ "http://.example./": { "ments": { "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./v1.0/395320319544/ments?limit=25&after=MjU0" } } } }
根据next的url再请求可以获取下一页的评论内容
代码如下:
<?php $url = 'http://.example./'; $api = 'https://graph.facebook./ments/?ids='; $result = json_decode(file_get_contents($api.urlencode($url)), true); print_r($result); ?>
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程