0
我試圖利用Facebook的實時更新API ...我有以下代碼:Facebook的實時資訊提供
<?php
define('VERIFY_TOKEN', '*');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' && $_GET['hub_verify_token'] == VERIFY_TOKEN) {
echo $_GET['hub_challenge'];
} else if ($method == 'POST') {
$hostname = "*";
$username = "*";
$dbname = "*";
$password = "*";
mysql_connect($hostname, $username, $password) OR DIE('Unable to connect to database! Please try again later.');
mysql_select_db($dbname) or die(mysql_error());
$post_body = file_get_contents("php://input");
$object = json_decode($post_body, true);
foreach ($object->entry as $update) {
// For each entry in notification, insert a row of information into the table "FaceBook"
$changed_fields = $update->changed_fields[0];
$result = mysql_query("INSERT INTO FaceBook (uid, id, time, changed_fields) VALUES('$update->uid', '$update->id', '$update->time', '$changed_fields')")
or die(mysql_error());
}
mysql_close();
}
?>
現在,當更新發生,Facebook是發送POST請求,但在foreach循環沒有被輸入...我試圖檢查$對象是否爲空,但它返回2個元素(使用計數)..
任何想法?