Php 创建新帖子时收到通知

Php 创建新帖子时收到通知,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我正在寻找一种方法,每当有新帖子创建时,都可以从facebook获得通知。 到目前为止,我找到的唯一解决方案是每隔几分钟检查一次cron作业。 facebook sdk不提供这样的方法吗 感谢使用Facebook Graph API订阅 您所指的权限user\u subscriptions与实时更新没有任何关系–它是关于“follow”功能,读取用户订阅了谁/订阅了谁… <?php $app_id = 'YOUR_APP_ID'; $app_secret = 'YOUR_APP

我正在寻找一种方法,每当有新帖子创建时,都可以从facebook获得通知。 到目前为止,我找到的唯一解决方案是每隔几分钟检查一次cron作业。 facebook sdk不提供这样的方法吗


感谢使用Facebook Graph API订阅


您所指的权限
user\u subscriptions
与实时更新没有任何关系–它是关于“follow”功能,读取用户订阅了谁/订阅了谁…
<?php

  $app_id = 'YOUR_APP_ID';
  $app_secret = 'YOUR_APP_SECRET';
  $app_url = 'http://YOURAPPURL';
  $fields = 'feed';
  $verify_token = 'YOURVERIFYTOKEN';

  // Fetching an App Token
  $app_token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
                   .$app_id.'&client_secret='.$app_secret
                   .'&grant_type=client_credentials';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $app_token_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $res = curl_exec($ch);
  parse_str($res, $token);

  if (isset($token['access_token'])) {
    // Let's register a callback
    $params = array(
      'object'
        =>  'user',
      'fields'
        =>  $fields,
      'callback_url'
        // This is the endpoint that will be called when
        // a User updates the location field
        =>  $app_url . '/index.php?action=callback',
      'verify_token'
        =>  $verify_token,
    );

    curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'
                                  .$app_id.'/subscriptions?access_token='
                                  .$token['access_token']);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    $res = curl_exec($ch);
    if ($res && $res != 'null') {
      print_r($res);
    }

    // Fetch list of all callbacks
    curl_setopt($ch, CURLOPT_POST, 0);
    $res = curl_exec($ch);
  }
  if ($res && $res != 'null') {
    print_r($res);
  }
  curl_close($ch);

?>