Home >Backend Development >PHP Tutorial >Example tutorial of adding Facebook comment plug-in to the page of PHP site, facebook example tutorial_PHP tutorial

Example tutorial of adding Facebook comment plug-in to the page of PHP site, facebook example tutorial_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:01:061369browse

An example tutorial on adding Facebook comment plug-in to the page of a PHP site, facebook example tutorial

First, you need to create an APP on facebook. For the creation method, see https://developers. facebook.com/, the APP has an item to fill in the Domain, fill in the Domain of your website here. (The APP is bound to the domain and cannot be filled in randomly)
Then you can use facebook comments plugins.

Using facebook comments plugins, facebook comments can be inserted into the page.
Generate code method: https://developers.facebook.com/docs/plugins/comments

For example: There is a page called http://www.example.com/. Insert the following code into this page to use 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> 

Displayed as follows on the page

201618151749286.jpg (626×359)

Read the total number of shares and comments on the page

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

{YOUR_URL} requires urlencode
For example: https://graph.facebook.com/?ids=http://www.example.com/
Return:

{ 
  "http://www.example.com/": { 
   "id": "http://www.example.com/", 
   "shares": 399517, 
   "comments": 392 
  } 
} 

The code is as follows:

<&#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;> 

Read page comment list

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

{YOUR_URL} requires urlencode
For example: https://graph.facebook.com/comments/?ids=http://www.example.com/
Return:

{ 
  "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" 
     } 
   } 
  } 
} 

Request according to the next url to get the comment content of the next page

The code is as follows:

<&#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;> 

Articles you may be interested in:

  • Detailed explanation of the PHP function in WordPress that calls comment templates and loops to output comments
  • Explains the functions in WordPress used to obtain comment templates and search forms PHP function
  • Write a PHP script to implement the comment pagination function in WordPress
  • Example of how to modify the PHP script to enable WordPress to intercept spam comments
  • Comment top implemented by PHP combined with jQuery. Dislike function
  • How to use AngularJS and PHP’s Laravel to implement single-page comments
  • How to use the Duoshuo comment plug-in on ThinkPHP
  • PHP implements the use of Chinese character ratio to judge garbage Method of commenting
  • PHP uses strstr() function to prevent spam comments (by judging a mark)
  • Code of using Akismet in php to prevent spam comments

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1089946.htmlTechArticleAn example tutorial of adding Facebook comment plug-in on the page of PHP site, facebook example tutorial First, you need to create a facebook comment plugin APP, please see https://developers.facebook.com/ for the creation method,...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn