Instagram Real time updates tag - getting empty data, why?

此生再无相见时 提交于 2019-11-30 07:33:58

Instagram Realtime API subscription will only let you know when there has been an update to your subscribed object, not what the update is. Once you receive a notification, it is up to you to make a call to the API (in your case probably https://api.instagram.com/v1/tags/winter/media/recent ) and to see what the new content is.

Depending on the volume of changes, you will probably want to batch these calls up at certain time intervals, but the below should be a good start. You'll also probably only want to retrieve items you haven't already retrieved.

<?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);
    }

}
?>

I get the $_POST to say there is an update from one of authenticated users, problem is there are 153 of them subscribed to the feed. The only way to get check if a user has an update is to get their latest.

I also can post a photo on IG myself. The $_POST is received triggering the loop of users being polled but the newest item won't show up in the api at the same time as the $_POST trigger arrives from the real-time api.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!