Instagram Real time updates tag - callback called

2019-04-22 06:54发布

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?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-04-22 07:49

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.

查看更多
登录 后发表回答