Heim > php教程 > php手册 > Hauptteil

在PHP站点的页面上添加Facebook评论插件的实例教程,facebook实例教程

WBOY
Freigeben: 2016-06-13 08:48:00
Original
953 Leute haben es durchsucht

在PHP站点的页面上添加Facebook评论插件的实例教程,facebook实例教程

首先,需要在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。

<!-- 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> 
Nach dem Login kopieren

在页面上显示如下

读取页面的分享总数与评论总数

https://graph.facebook.com/&#63;ids={YOUR_URL} 
Nach dem Login kopieren

{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 
  } 
} 
Nach dem Login kopieren

代码如下:

<&#63;php 
$url = 'http://www.example.com/'; 
$api = 'https://graph.facebook.com/&#63;ids='; 
 
$result = json_decode(file_get_contents($api.urlencode($url)), true); 
 
print_r($result); 
&#63;> 
Nach dem Login kopieren

读取页面评论列表

https://graph.facebook.com/comments/&#63;ids={YOUR_URL} 
Nach dem Login kopieren

{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&#63;limit=25&after=MjU0" 
     } 
   } 
  } 
} 
Nach dem Login kopieren

根据next的url再请求可以获取下一页的评论内容

代码如下:

<&#63;php 
$url = 'http://www.example.com/'; 
$api = 'https://graph.facebook.com/comments/&#63;ids='; 
 
$result = json_decode(file_get_contents($api.urlencode($url)), true); 
 
print_r($result); 
&#63;> 
Nach dem Login kopieren

您可能感兴趣的文章:

  • 详解WordPress中调用评论模板和循环输出评论的PHP函数
  • 讲解WordPress中用于获取评论模板和搜索表单的PHP函数
  • 编写PHP脚本来实现WordPress中评论分页的功能
  • 修改PHP脚本使WordPress拦截垃圾评论的方法示例
  • PHP结合jQuery实现的评论顶、踩功能
  • 使用AngularJS和PHP的Laravel实现单页评论的方法
  • ThinkPHP上使用多说评论插件的方法
  • PHP实现通过中文字符比率来判断垃圾评论的方法
  • PHP用strstr()函数阻止垃圾评论(通过判断a标记)
  • php中使用Akismet防止垃圾评论的代码
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!