php - 使用 cURL 的 Bug 订阅 instagram API

标签 php api curl instagram

这是我订阅/取消订阅实时 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/

相关文章:

PHP上传路径中没有斜杠

python - 以下哪项是请求 API 的好方法?

api - 如何在 TeamCity 中的特定构建上添加网络 Hook

php - 我可以使用 cURL 获取 html 表格吗?

php - 从Docker容器向PHP添加扩展

php - 使用列的值保存变量

php - 如何根据MySQL中的另一列有条件地选择列

php - 如何在另一个字符串中插入一个字符串?

c++ - 在 C++ 程序中调用 Python 函数

php - php脚本是如何执行的