脸书API实时更新v2.2读取更新


Facebook API Real Time update v2.2 read update

我在用php工作我做了工作和sottoiscrizione

Facebook API 是 v.2.2

但现在有一个问题如何阅读我获得的提要的更新?

代码是:

<?php
//file of program
require_once('LoginFb.php'); 
require_once('FbClass.php');
require_once('dbClass.php');
require_once('FacebookClass.php');
//receive a Real Time Update
$method = $_SERVER['REQUEST_METHOD'];                             
// In PHP, dots and spaces in query parameter names are converted to 
// underscores automatically. So we need to check "hub_mode" instead
//  of "hub.mode".                                                      
if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' &&       
    $_GET['hub_verify_token'] == 'thisisaverifystring') {
    echo $_GET['hub_challenge'];    //print the code on the page that Facebook expects to read for confirmation
} else if ($method == 'POST') {                                   
  $updates = json_decode(file_get_contents("php://input"), true); 
  // Replace with your own code here to handle the update 
  // Note the request must complete within 15 seconds.
  // Otherwise Facebook server will consider it a timeout and 
  // resend the push notification again.
  $testo=json_decode($updates["entry"]);

  $var=fopen("nome_file.txt","a+");
  fwrite($var, "ciao");
  fwrite($var, $updates );
  fclose($var);

  error_log('updates = ' . print_r($updates, true));              
}
?>

在上面的文件中,"$update"包含更新的提要,但如何提取?

注意:订阅工作和更新到达我的服务器。

请帮帮我:)

根据Facebook文档[链接]:
请注意,实时更新仅指示特定字段已更改,它们不包括这些字段的值。它们应仅用于指示何时需要向该字段发出新的图形 API 请求。

因此,您不会获得更新的数据,而是获得更新的字段名称。收到更新后,应提取更改的字段(我在下面对此进行了解释)并向该字段发出新的图形 API 请求。最后,您将获得更新的字段数据。

如何提取用户名和更改的字段?您会收到以下内容:

{"entry":[{"id":"****","uid":"****","time":1332940650,"changed_fields":{"status"]}],"object":"user"}

其中"id"是我的pageId,"changed_fields"是更改字段的数组。您可以按如下方式提取这些内容:

$entry = json_decode($updates["entry"]); <br>
$page = json_decode($entry["uid"]); <br>
$fields = json_decode($entry["changed_fields"]);

希望对您有所帮助! :)

没有函数 -> respose 包含一个数组数组,正确的代码是:

$json = json_decode($updates["entry"][0]["uid"], true);