这是我订阅/取消订阅实时 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 已正确包含。</p>
我花了很多时间尝试修复它,但没有办法。 您能帮我完成订阅吗?
如果您需要更多详细信息,请询问我。
非常感谢
最佳答案
好的,我修复了它:我认为我们应该在 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);
关于php - 使用 cURL 的 Bug 订阅 instagram API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12168366/