Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook real-time updates
    primarykey
    data
    text
    <p>I was trying to implement the FB Real-Time Updates. I guess I have managed to subscribe, but don't get any updates... Here is my code:</p> <p><strong>For getting App access token</strong></p> <pre><code>function authAsApp() { $config = array ('appId' =&gt; FB_APPID, 'secret' =&gt; FB_SECRET); $fb = new Facebook($config); Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; $args = array('grant_type' =&gt; 'client_credentials', 'client_id' =&gt; APP_ID, 'client_secret' =&gt; APP_SECRET); $ch = curl_init(); $url = 'https://graph.facebook.com/oauth/access_token'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); $returnValue = curl_exec($ch); curl_close($ch); $appAccessToken = substr($returnValue, strpos($returnValue,"=")+1); var_dump($appAccessToken); return $appAccessToken; } </code></pre> <p><strong>For subscribtion</strong></p> <pre><code>function subscribeTo($access_token) { $param = array('access_token' =&gt; $access_token, 'object' =&gt; 'user', 'fields' =&gt; 'name, feed, likes', 'callback_url' =&gt; 'http://mysite.com/realTimeVerification.php', 'verify_token' =&gt; VERIF_STR ); $config = array ('appId' =&gt; FB_APPID, 'secret' =&gt; FB_SECRET); $fb = new Facebook($config); Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; try { $subs = $fb-&gt;api('/'.APP_ID.'/subscriptions', 'POST', $param); var_dump($subs); } catch (\FacebookApiException $e) { echo $e-&gt;getCode()." ".$e-&gt;getType()." ".$e-&gt;getMessage()." ".$e-&gt;getFile()." ".$e-&gt;getLine()."\n"; } } </code></pre> <p><strong>In the callback file named realTimeVerification.php I have</strong></p> <pre><code>&lt;?php define('UPD_FILE', 'updates.log'); $method = $_SERVER['REQUEST_METHOD']; global $log_file; if ($method == 'GET' &amp;&amp; $_GET['hub_mode'] == 'subscribe' &amp;&amp; $_GET['hub_verify_token'] == 'BRComm') { echo $_GET['hub_challenge']; exit; } else if ($method == 'POST') { $log_file=UPD_FILE; $updates = json_decode(file_get_contents("php://input"), true); logToFile("updates =".print_r($updates)); } function logToFile($message){ global $log_file; $hdl = fopen($log_file, 'a') or die ("couldn't open log file"); fwrite($hdl,$message."\n"); fclose($hdl); } ?&gt; </code></pre> <p>After subscription I check it in Graph API Explorer and get:</p> <pre><code>{ "data": [ { "object": "user", "callback_url": "http://mysite.com/realTimeVerification.php", "fields": [ "feed", "name" ], "active": true } ] } </code></pre> <p>So it's subscribed. But when I do changes to my user that has authenticated the App, I don't get any changes in the log. What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload