Advertisement
ghadeerprince

Untitled

Jan 14th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2. $verify_token = "samconnection";
  3.   if ($_REQUEST['hub_verify_token'] == $verify_token) {
  4.   echo $_REQUEST['hub_challenge'];
  5.   }
  6.  
  7. require_once 'facebook_sdk/src/Facebook/autoload.php';
  8. $input = json_decode(file_get_contents('php://input'), true);
  9. if($input['entry'][0]['changes'][0]['value']['item'] == "comment" && !empty($input['entry'][0]['changes'][0]['value']['message'])){
  10. $sender = $input['entry'][0]['changes'][0]['value']['from']['id'];
  11. $page_id = $input['entry'][0]['id'];
  12. if($sender != $page_id):
  13. $accesstoken = '**************';
  14. $post_id = $input['entry'][0]['changes'][0]['value']['post_id'];
  15. $parent_id = $input['entry'][0]['changes'][0]['value']['parent_id'];
  16. if($parent_id == $post_id):
  17. $cid = $input['entry'][0]['changes'][0]['value']['comment_id'];
  18. $message = "-";
  19.     $fb = new Facebook\Facebook([
  20.   'app_id' => '************',
  21.   'app_secret' => '**********',
  22.   'default_graph_version' => 'v5.0',
  23.   ]);
  24. if( !empty($input['entry'][0]['changes'][0]['value']['message'])):
  25. try {
  26.   // Returns a `Facebook\FacebookResponse` object
  27.   $response = $fb->post(
  28.     '/'.$cid.'/comments',
  29.     array (
  30.         'message' => '@['.$sender.'] welcome in our page'
  31.         ),
  32.     $accesstoken
  33.   );
  34. } catch(Facebook\Exceptions\FacebookResponseException $e) {
  35.   echo 'Graph returned an error: ' . $e->getMessage();
  36. } catch(Facebook\Exceptions\FacebookSDKException $e) {
  37.   echo 'Facebook SDK returned an error: ' . $e->getMessage();
  38. }
  39. endif;
  40. if(!empty($message)):
  41. //$response = $fb->get('/'.$post_id.'/full_picture',$accesstoken);
  42. //$pic =$response->getGraphNode();
  43. $jsonData = '{
  44.   "recipient":{
  45.       "comment_id":"'.$cid.'"
  46.   },
  47.   "message": 'thank you for commenting'
  48.  
  49. }';
  50.  
  51. $url = 'https://graph.facebook.com/v5.0/me/messages?access_token='.$accesstoken;
  52. $ch = curl_init($url);
  53. curl_setopt($ch, CURLOPT_POST, 1);
  54. curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
  55. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  56. if($r==true){
  57.   $plan->UpdateRepliesCount($post_id,$count);
  58.   $result = curl_exec($ch);
  59. }
  60. curl_close($ch);
  61. endif;
  62. endif;
  63. endif;
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement