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

后端 未结 2 472
滥情空心
滥情空心 2020-12-30 16:12

Heloo,

I am working on one project and I need real time updates from Instagram for certain tag.

This is my code for Create a Subscription

&l         


        
相关标签:
2条回答
  • 2020-12-30 16:56

    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.

    0 讨论(0)
  • 2020-12-30 17:01

    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);
        }
    
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题