簡體   English   中英

Facebook 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文檔[link]
請注意,實時更新僅指示特定字段已更改,不包括這些字段的值。 它們僅應用於指示何時需要對該字段進行新的Graph API請求。

因此,您不會獲取更新的數據,而是會獲取更新的字段名稱。 收到更新后,您應該提取更改的字段(我在下面對此進行了解釋),並對該字段提出了新的Graph 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包含一個array數組,正確的代碼是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM