Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Realtime Update API for page feed

I have gone through Realtime Update API documentation provided by Facebook & got successfully subscribed to the "page" object with the field as "feed", below is subscription url check which I used

URL:- https://graph.facebook.com//subscriptions?access_token=

which gave me the following response

RESPONSE:-

{
    "data": [
        {
            "object": "page",
            "callback_url": <CALLBACK_URL>,
            "fields": 
[
                "feed"
            ],
            "active": true
        }
    ]
}.

This response clearly states that App is subscribed for feeds on the pages.

But my problem is that I am unable to receive any RealTime Update on the .

Below is the CALLBACK_URL php file code

<?php
    define('VERIFY_TOKEN', <APPSECRET_KEY>);                                    
    $method = $_SERVER['REQUEST_METHOD'];

    if(!empty($method))
    {
        if (!empty($_GET) && strcmp($method, 'GET') == 0 && strcmp($_GET['hub_mode'], 'subscribe') == 0 && $_GET['hub_verify_token'] == VERIFY_TOKEN) 
        {   
            echo $_GET['hub_challenge'];
        } 
        else if (strcmp($method, 'POST') == 0) 
        {
            file_put_contents(<FILE_PATH1>, "inside post method");   
            if (isset( $_SERVER['HTTP_X_HUB_SIGNATURE'] ) ) 
            {
                file_put_contents(<FILE_PATH2>, "inside post method");
                $post_body = file_get_contents("php://input");

                $object = json_decode($post_body);
                file_put_contents(<FILE_PATH3>, json_encode($object));
                if ($_SERVER['HTTP_X_HUB_SIGNATURE'] == "sha1=" . hash_hmac('sha1', $post_body, VERIFY_TOKEN)) 
                {
                    //REST OF THE CODE TO SAVE IN DB
                }
            }
        }
    }
    else
    {
        echo "Invalid Request, might be for testing purpose";
    }
?>

Facebook is not sending any POST request to my CALLBACK_URL. Please let me know if I am missing anything

like image 581
Ganesh Deshvini Avatar asked Dec 10 '14 12:12

Ganesh Deshvini


1 Answers

Finally I found the answer, just made a POST request to the below URL

https://graph.facebook.com/PAGE_ID/tabs?app_id=APP_ID&access_token=PAGE_ACCESS_TOKEN

I then started receiving Facebook Realtime Updates

like image 179
Ganesh Deshvini Avatar answered Nov 03 '22 03:11

Ganesh Deshvini