2014-11-18 2 views
0

업데이트 읽을페이스 북 API 실시간 업데이트 버전 2.2가 내가 작업과 sottoiscrizione했다 PHP 에서 일하는

페이스 북의 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));    
} 

?> 

업데이트 된 피드를 포함하고 있지만, 압축을 해제하는 방법?

참고 : 가입 WORKS 및 업데이트가 내 서버에 도착했습니다. 내가 페이스 북의 문서 [link]에 따르면

답변

0

을 :)하십시오

도움말 : 실시간 업데이트는 특정 필드가 변경된 것을 나타내는 것을
주, 그들은 그 필드의 값을 포함하지 않습니다. 해당 필드에 대한 새 Graph API 요청이 만들어 질 필요가있을 때만 표시해야합니다.

업데이트 된 데이터를 얻지 못하고 업데이트 된 feild 이름을 얻습니다. 업데이트를 받으면 변경된 필드 (아래에서 설명 함)를 추출하고 해당 필드에 새 Graph API 요청을 만들어야합니다. 마지막으로 업데이트 된 필드 데이터를 가져옵니다.

사용자 이름과 변경된 필드를 추출하는 방법은 무엇입니까? 당신이받는이 :
"ID"내 페이지 id이고 "changed_fields는"변경 필드의 배열입니다

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

. 다음과 같이 추출 할 수 있습니다.

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

희망이 있습니다. 내가 게시 된 게시물의 ID를 반환하는 대신한다는 것을 필요 ...

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

덕분에 죄를 : - :

기능 없음>는 respose 올바른 코드가 배열의 배열을 포함 그것을 허용하지 ... 괜찮아 내가/나/피드를 요청하고 첫 번째 게시물을 확인합니다 :) – Bonni

+0

Edhiv ... JSON의 ID를 추출하는 이유는 무엇입니까? ... 나는 사용자 ID를 추출하는 문제가있다 – Bonni

+0

나는 내 대답을 업데이트했다. "id"를 "uid"로 변경했습니다. 도움이된다면 대답을 수락하십시오. – abhinav