dpxpz37157 2017-03-14 01:06
浏览 616
已采纳

Instagram-API ::: cURL错误18:传输关闭,剩余3789字节读取

I get this error in the middle of data mining from instagram (basically ~8000 images and comments were retrieved correctly and suddenly I receive the following error):

 cURL error 18: transfer closed with 3789 bytes remaining to read (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

The only part I have used curl in my code is:

function url_exists($url) {
    if (!$fp = curl_init($url)) return false;
    return true;
}

and the url is used here:

        $feed_img_url = $feed[$idx]->getImageVersions2()->candidates[0]->getUrl()."
";
        if (url_exists($feed_img_url)==true) {
            $img = "results/".$feed_id_str."/".$feed_id_str.".jpeg";
            file_put_contents($img, file_get_contents($feed_img_url));
        }

It doesn't tell which line is producing the error but I guess this exception is coming from one of the above as I haven't used the url anywhere else. This part $feed[$idx]->getImageVersions2()->candidates[0]->getUrl()." "; is from Instagram PHP API as in https://github.com/mgp25/Instagram-API

Please suggest fixes to this problem.

Further information: This happens when retrieving data from https://www.instagram.com/gegengrader/ while it doesn't have many posts, posts have lots of likes and only 29 of the posts(images) were retrieved. That said, I am not confident if this is an API rate-limit problem or not. If it is, let me know how to get it fixed.

  • 写回答

1条回答 默认 最新

  • dqzve68846 2017-03-14 02:56
    关注

    So I realized when I am browsing this instagram account manually, not everything loads anyways and it takes a long time to load it. I used these and now at least I retrieve 70 of 130ish feeds:

    function url_exists($url) {
        if (!$cURL = curl_init($url)) {
            return false;
        }
    
        curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Expect:'));
        return true;
    }
    

    and

    catch (Exception $e) {
        echo $e->getMessage();
        if (strpos($e->getMessage(), 'cURL error 18: transfer closed') !== false) {
            continue;
        }
    
    }
    

    Possibly not the best solution but it serves my needs. Please feel free to add your answers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算