2

The endpoint for deleting realtime subscriptions seems to have stopped working. I'm performing a cURL 'POST' with a 'DELETE' custom request and receiving the following JSON response from Instagram:

{"meta":{"code":200},"data":null}

However, the subscription is not deleted. My count of active subscriptions will never decrease, and I cannot subscribe to new object types.

Is anyone else having this issue? Here's my implementation in PHP (working fine for months, until a few days ago):

$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, "https://api.instagram.com/v1/subscriptions? client_secret=$client_secret&client_id=$client_id");
curl_setopt($curl, CURLOPT_POST, false);
$resp = curl_exec($curl);

//  Parse JSON                                                                                                                                                                          \

$json = json_decode($resp);

foreach ($json->data as $subscription)
{
echo "DELETING:\r\n";
echo "object:\t$subscription->object\r\n";
echo "object_id:\t$subscription->object_id\r\n";
echo "aspect:\t$subscription->aspect\r\n";
echo "callback URL:\t$subscription->callback_url\r\n";
echo "type:\t$subscription->type\r\n";
echo "id:\t$subscription->id\r\n\r\n";

curl_setopt($curl, CURLOPT_URL, "https://api.instagram.com/v1/subscriptions?client_secret=$client_secret&client_id=$client_id&id=$subscription->object_id");
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
$resp = curl_exec($curl);

echo $resp."\r\n";
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • I'm only new to the Instagram API, so have no evidence of this working previously, but I also seem to be having problems deleting subscriptions. Did you manage to work out what was happening here? – Steve Weaver Crawford Feb 06 '14 at 23:38
  • Not yet. I filed a support request with Instagram months ago. For a while I thought I was the only one. I still cannot delete all of my realtime subscriptions. – brandonthorpe Feb 07 '14 at 16:07

1 Answers1

1

Through hours of trial and error with curl, I managed to get this working, it seems to be consistent and works all of the time. The main difference between yours and mine is the setting of these options:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POST, true);

As you can see, I set the CUSTOMREQUEST to "DELETE", but then also set POST to true, in that order. I am guessing that without setting POST to true, it will actually perform a GET (I could be very wrong there though). I also read on some SO answer about the order of curl options being important, so be wary there too. Below is my complete delete function, if $id is not provided, it will delete ALL subscriptions, so watch out there.

public function delete($id = "") {
    CakeLog::write('debug', 'Delete subscription called.');

    $clientID = "<<MY clientID>>";
    $clientSecret = "<<MY clientSecret>>";

    $deleteURL = "https://api.instagram.com/v1/subscriptions";
    $deleteParams = "?client_id=".$clientID."&client_secret=".$clientSecret;

    if ($id == "") {
        $deleteParams .= "&object=all";
    }
    else {
        $deleteParams .= "&id=".$id;
    }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $deleteURL.$deleteParams);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Should cURL return or print out the data? (true = return, false = print)
    $output = curl_exec($ch);
    curl_close($ch);

    CakeLog::write('debug', 'DELETE SUBSCRIPTION RESULT: ' . $output);

    $this->redirect(array('action' => 'index'));

}

Please let me know how it goes, and good luck

  • Thanks for the post. It's still not working for me. I'm wondering if there's a problem specific to my API access credentials. What are you seeing as the output of the curl_exec call on your end? – brandonthorpe Feb 07 '14 at 20:35
  • I get the same response as you, but it does work - {"meta":{"code":200},"data":null}. How are you checking that your subscriptions still exist? – Steve Weaver Crawford Feb 07 '14 at 22:52
  • i get 500 server error. $output is null. I think delete function is not working instagram http://developers.instagram.com/post/82701625883/api-returning-500-errors-on-specific-ip – neoerol Feb 21 '15 at 19:22