0

Facebook Realtime Updates 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 つの要素が返されます (count を使用)。

何か案は?

4

1 に答える 1

0

これにもいくつかの問題がありました。

すべてのオブジェクトには多数のエントリがあります。すべてのエントリには、私が信じているいくつかの変更があります。したがって、「変更」もエントリと同様に配列です。

これを試して:

foreach($object->entry as $update){

    foreach($update->changes as $change){

        //access information about the change that occured on the page

    }
}
于 2013-11-27T09:37:14.417 に答える