我正在尝试使用 Facebook 实时更新 API ...我有以下代码:
<?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 循环......我试图检查 $object 是否为空,但它返回 2 个元素(使用计数)..
有任何想法吗?