doumei9589 2014-09-29 16:31
浏览 57

来自Facebook的实时页面更新

I have a web application which needs to fetch the real time updates to a particular page. I have gone through a lot of questions on this forums and yet not found anything that works for me. When I subscribe to the page updates

I am supplying valid app_id, app_secret and app_url.

 <?php

  $app_id = '';
  $app_secret = '';
  $app_url = '';
  $fields = 'feed';
  $verify_token = 'abcd@123';

  // 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'
        =>  'page',
      '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);
    error_log('updates = ' . print_r($res, true));
  }
  curl_close($ch);

?>

the FB posts to my callback URL but doesn't send the id of the post which was updated, instead it sends the user id in both the id as well as the uid. Even the updates are irregular, sometimes there is a notification, at other times no notification.

What do I need to do make this work?

  1. There is something about whitelisting apps -- does that need to be done.
  2. Do I need to make this app as a facebook app and have the page install this app on a tab?
  3. Do I need special permission to be granted by the page admin.
  4. Can this be done at all?

Any help would be very welcome. Thanks!!

A similar question on this forum :Facebook Real Time Update return only "changed_fields":["feed"] and not the actual comment

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)