Php Instagram实时更新标签-获取空数据,为什么?

Php Instagram实时更新标签-获取空数据,为什么?,php,json,api,instagram,Php,Json,Api,Instagram,你好 我正在做一个项目,我需要Instagram对某些标签进行实时更新 这是我创建订阅的代码 <?php $client_id = 'MOJID'; $client_secret = 'MOJIDSECRET'; $redirect_uri = 'http://example.net/instagram/callback.php'; $apiData = array( 'client_id' => $client_id,

你好

我正在做一个项目,我需要Instagram对某些标签进行实时更新

这是我创建订阅的代码

<?php
    $client_id = 'MOJID';
    $client_secret = 'MOJIDSECRET';
    $redirect_uri = 'http://example.net/instagram/callback.php';
    $apiData = array(
        'client_id' => $client_id,
        'client_secret' => $client_secret,
        'redirect_uri' => $redirect_uri,
        'aspect' => "media",
        'object' => "tag",
        'object_id' => "winter",
        'callback_url' => $redirect_uri
    );

    $apiHost = 'https://api.instagram.com/v1/subscriptions/';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $apiHost);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($apiData));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $jsonData = curl_exec($ch);
    curl_close($ch);
    var_dump($jsonData);
?>
这是callback.php的代码:

<?php
    if (isset ($_GET['hub_challenge'])){
        echo $_GET['hub_challenge'];
    }
    else{
        $myString = file_get_contents('php://input');
        $ALL = $myString."\r\n";
        file_put_contents('activity.log', $ALL, FILE_APPEND | LOCK_EX);
    }
?>

activity.log中的一行是:

[{“已更改的方面”:“媒体”,“对象”:“标记”,“对象id”:“冬季”,“时间”:1385411793,“订阅id”:3932963,“数据”:{}]

我获得了正确的订阅id,但数据为空。 另外,访问日志看起来像:

54.209.52.224--[25/Nov/2013:20:59:20+0100]“POST/instagram/callback.php HTTP/1.0”200 231“-”Python-httplib2/0.7.4(gzip)”

这很好,状态代码是200,但数据还是空的。Instagram正在“提交”我的回调文件,但数据为空


我做错了什么?

Instagram Real Time API订阅只会让您知道您订阅的对象何时有更新,而不是更新内容。一旦收到通知,您就可以调用API(在您的情况下可能是
https://api.instagram.com/v1/tags/winter/media/recent
)并查看新内容

根据更改的数量,您可能希望在特定的时间间隔批处理这些调用,但下面的内容应该是一个好的开始。您也可能只想检索尚未检索的项目

<?php
if (isset ($_GET['hub_challenge'])){
    echo $_GET['hub_challenge'];
}
else{
    $myString = file_get_contents('php://input');
    $sub_update = json_decode($myString);

    $access_token = '{ previously saved, get this from DB or flatfile }';

    foreach($sub_update as $k => $v) // can be multiple updates per call
    {
        $recent_data = file_get_contents('https://api.instagram.com/v1/tags/'.$sub_update->object_id.'/media/recent?access_token='.$access_token);
        file_put_contents('activity.log', serialize($recent_data->data), FILE_APPEND | LOCK_EX);
    }

}
?>

我收到$\u的帖子说有一个经过身份验证的用户更新了,问题是有153个用户订阅了该提要。检查用户是否有更新的唯一方法是获取其最新更新


我也可以在IG上发布自己的照片。接收到$u POST会触发被轮询用户的循环,但最新的项目不会在实时api发出$u POST触发器的同时显示在api中。

@cdbconcepts这是否意味着如果您订阅用户,您需要检查每个用户的更新,而不是获取用户的id进行更新和检查他们。我目前的问题是,我无法将返回的带有id的JSON放入PHP数组中,请参见:
<?php
if (isset ($_GET['hub_challenge'])){
    echo $_GET['hub_challenge'];
}
else{
    $myString = file_get_contents('php://input');
    $sub_update = json_decode($myString);

    $access_token = '{ previously saved, get this from DB or flatfile }';

    foreach($sub_update as $k => $v) // can be multiple updates per call
    {
        $recent_data = file_get_contents('https://api.instagram.com/v1/tags/'.$sub_update->object_id.'/media/recent?access_token='.$access_token);
        file_put_contents('activity.log', serialize($recent_data->data), FILE_APPEND | LOCK_EX);
    }

}
?>