2

this is my first question to stackoverflow, so if's something wrong please advise.. Well the problem is Facebook real time updates : I have successfully created subscription to page and it's admin user ( test page and test app created ), user has agreed permissions to manage_page, read_stream, read_friendlist, read_insights,publish_actions and a lot of user's data ( about,email etc etc ) When i query GET to Graph api with edge /subscriptions i get the result :

{
  "data": [
    {
      "object": "user", 
      "callback_url": "LIVE_CALLBACK_URL", 
      "fields": [
        "feed"
      ], 
      "active": true
    }, 
    {
      "object": "page", 
      "callback_url": "LIVE_CALLBACK_URL", 
      "fields": [
        "built", 
        "description", 
        "email", 
        "feed", 
        "location", 
        "name", 
        "personal_info", 
        "written_by"
      ], 
      "active": true
    }
  ]
}

So, that's taken care of, after that i searched why Facebook isn't sending me any updates ( which I log to somefile.txt ) So i found out you need to query the Graph api with /tabs to create page tab for my api. When i query that it returned "success" so that's created ( can't find out where it's stored, but it working ... ). After that i have created some data on my profile, to test and also on the page to see if the Facebook is sending any updates, and it's suddenly send one update that was comment on my user profile post ( shared on timeline ). The response was :

14:17 05.02.2015
Array
(
    [object] => user
    [entry] => Array
        (
            [0] => Array
                (
                    [uid] => ****my_fb_id****
                    [id] => ****my_fb_id - not_someone_else****
                    [time] => 1423146339
                    [changed_fields] => Array
                        (
                            [0] => feed
                        )

                )

        )

)

So Facebook send's the empty feed, and it's ok, probably some permissions or something else, but after that i have made more posts and ppl commented on it ( on user profile and test page ) but Facebook didn't send any updates, or any call to my web page. So has anyone facing this problem in the past, and how he solved that ? The part that is for receiving the update from Facebook is :

$method = $_SERVER['REQUEST_METHOD']; 
    if(isset($_GET['hub_mode']) && isset($_GET['hub_verify_token'])){
          if (trim($method) == 'GET' && trim($_GET['hub_mode']) == 'subscribe' && trim($_GET['hub_verify_token']) == VERIFY_TOKEN) {
            print $_GET['hub_challenge'];
          }
      }
      else if ($method == 'POST') {      
        $updates = json_decode(file_get_contents("php://input"), true); 
            $file = 'log.txt';
            $current = file_get_contents($file);
            @$results = print_r($updates,true);
            $current .=  $results;
            file_put_contents($file, $current);                             
    }

I have tried to detail my problem as much i as could... Searched but don't really understand why it's not working.

crazy_ljuba
  • 104
  • 8
  • You don't need a page tab app. – WizKid Feb 05 '15 at 21:08
  • Without that it wasn't sending any update to web page ( saw it here [link](http://stackoverflow.com/questions/21189046/subscribe-to-facebook-page-feed-real-time-updates) ) that's why i added the page tab, and it worked, but only once... – crazy_ljuba Feb 05 '15 at 21:24
  • That way of subscribing for real-time updates for pages is outdated. Check out the current method here: https://developers.facebook.com/docs/graph-api/real-time-updates/v2.2 – CBroe Feb 05 '15 at 23:37
  • @CBroe, what's the new approach to build subscriptions ? via some frameworks ? – crazy_ljuba Feb 06 '15 at 09:55
  • How about you click on the link I posted and read about it …? – CBroe Feb 06 '15 at 10:27

1 Answers1

0

Apart from using an outdated method as @CBroe outlined, I think you have a misunderstanding: Facebook will not send you the data that has changed, but the object (and it's fields/edges) the change occurred for User object changes.

For Pages, you can receive the changes itself (changed_fields vs. changes fields in the FB request).

See

Once a subscription is successfully created, Facebook will make an HTTP POST request to your callback URL every time that there are changes (to the chosen fields or edges).

That means you need to contruct a separate request from the info object you get from Facebook. In your example it would be a request to your user's feed

GET /{user_id}/feed

to query for recent changes.

Tobi
  • 31,405
  • 8
  • 58
  • 90
  • what's the new approach to build subscriptions ? via some frameworks ? Thanks for clarification, never thought that, that kind of update will be expected from Facebook, in that case, it was working only once :) Why isn't any updates coming for the page ? – crazy_ljuba Feb 06 '15 at 09:55
  • have a look at https://developers.facebook.com/docs/graph-api/reference/v2.2/app/subscriptions#publish – Tobi Feb 06 '15 at 10:42
  • So i have to create a new subscriptions every time when i receive one ? Part about receiving was just to test it if it's working... e.g. i get the update from fb, query the graph with the edge i got, and then handle that query, and then recreate subscription ? – crazy_ljuba Feb 06 '15 at 10:53
  • No, one subscription per object/app is enough. It's all in the docs! – Tobi Feb 06 '15 at 12:10
  • thanks man, helped me a lot, made it work, it's sending the updates to the log file :) Sorry for some stupid questions, just needed someone to guide me a little ... million thanks ! :D – crazy_ljuba Feb 06 '15 at 12:24