Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram Real time updates tag - callback called twice?

I am using instagram real time updates for tag, to get notification when someone tag media with specific tag. Subscription works fine, and im able to check subscription directly using https://api.instagram.com/v1/subscriptions?client_secret={cs}&client_id={cid}

Within callback i have something like

if (isset ($_GET['hub_challenge'])){
    echo $_GET['hub_challenge'];
}
else{
    $my_string = file_get_contents('php://input');
    $sub_update = json_decode($my_string);
    //do the rest of the things with data we fetched
}

}

But, this callback is executed twice from instagram side. So for example, if i subscribe to "winter" tag, and if someone publish media and tag it using that tag, instagram will send notification twice to callback file i specified during subscription (both calls are executed within few secs). Why instagram sending request twice to the callback? Anyone had similar issue?

like image 520
cool Avatar asked Dec 09 '14 14:12

cool


1 Answers

After debugging and investigation i found that call is sent from instagram twice if callback file is not executed fast enough.

Based on the documentation:

Also, you should acknowledge the POST within a 2 second timeout--if you need to do more processing of the received information, you can do so in an asynchronous task.

They will send second request in case they dont receive response on first request within 2 secs.

At the end, i had blank callback.php file with only "sleep" inside it and its called twice each time.

like image 119
cool Avatar answered Nov 15 '22 15:11

cool