使用cURL订阅instagram API Bug


Bug Subscription instagram API with cURL

这是我订阅/取消订阅实时Instagram API的代码。取消订阅有效,但订阅无效。我对cUrl不是很好,我只是使用了来自http://thegregthompson.com/instagram-real-time-api-php/还有一些额外的定制。

<?php
$url = "https://api.instagram.com/v1/subscriptions/";
$ch = curl_init();
if (isset($_GET['unsubscribe']))
{
    echo "unsubscribe";
    $url .= "?client_id=" . $config['instagram']['client_id'] . "&client_secret=" .                   
    $config['instagram']['client_secret'] . "&id=" . $_GET['tag'];
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
}
else
{
    $attachment =  array(
        'client_id' => $config['instagram']['client_id'],
        'client_secret' => $config['instagram']['client_secret'],
        'object' => 'tag',
        'object_id' => $_GET['tag'],
        'aspect' => 'media',
        'verify_token' => $config['instagram']['verify_token'],
        'callback_url'=> 'http://' . $_SERVER['HTTP_HOST'] . '/callback/endpoint.php'
    );
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
    curl_setopt($ch, CURLOPT_POST, true);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
print_r($result);
?>

$config包含正确。

我花了很多时间试图修复它,但没有办法。你能帮我订阅吗?

问我你是否需要更多的细节。

非常感谢

好的,我修复了它:我认为我们应该在CURLOPT_POSTFIELDS 之前设置CURLOPT_POST

纠正

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);

不正确

curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_POST, true);