PHP Curl函数没有';行不通

PHP Curl函数没有';行不通,php,curl,instagram-api,Php,Curl,Instagram Api,我对curl函数有一些问题。我正在使用curl获取Instagram帖子,但突然该功能停止工作。我尝试了各种各样的改变,但都没能成功 这就是功能: function cek($url) { $curl = curl_init(); /** * Setup headers - I used the same headers from Firefox version 2.0.0.6 * below was split up because php.net sai

我对
curl
函数有一些问题。我正在使用
curl
获取Instagram帖子,但突然该功能停止工作。我尝试了各种各样的改变,但都没能成功

这就是功能:

function cek($url) {
    $curl = curl_init();

    /**
     * Setup headers - I used the same headers from Firefox version 2.0.0.6
     * below was split up because php.net said the line was too long. 
     */
    $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
    $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // browsers keep this blank.

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com');
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($curl, CURLOPT_MAXREDIRS, 10); /* Max redirection to follow */
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
    curl_setopt($curl, CURLOPT_AUTOREFERER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);

    $html = curl_exec($curl); // execute the curl command
    curl_close($curl); // close the connection

    return $html; // and finally, return $html
}

function get_curl($url) {
    if(function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
        $output = curl_exec($ch);
        echo curl_error($ch);
        curl_close($ch);
        return $output;
    } else {
        return file_get_contents($url);
    }
}
#$var = cek('https://api.instagram.com/v1/tags/'.instagram_tag.'/media/recent?client_id='.intagram_clientid.'&count=2');
$var = get_curl('https://api.instagram.com/v1/tags/'.instagram_tag.'/media/recent?max_tag_id=11&min_tag_id=1&access_token='.intagram_token.'&callback=?');

$cek = json_decode($var);
这就是我调用函数的地方:

function cek($url) {
    $curl = curl_init();

    /**
     * Setup headers - I used the same headers from Firefox version 2.0.0.6
     * below was split up because php.net said the line was too long. 
     */
    $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
    $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // browsers keep this blank.

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com');
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($curl, CURLOPT_MAXREDIRS, 10); /* Max redirection to follow */
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
    curl_setopt($curl, CURLOPT_AUTOREFERER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);

    $html = curl_exec($curl); // execute the curl command
    curl_close($curl); // close the connection

    return $html; // and finally, return $html
}

function get_curl($url) {
    if(function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
        $output = curl_exec($ch);
        echo curl_error($ch);
        curl_close($ch);
        return $output;
    } else {
        return file_get_contents($url);
    }
}
#$var = cek('https://api.instagram.com/v1/tags/'.instagram_tag.'/media/recent?client_id='.intagram_clientid.'&count=2');
$var = get_curl('https://api.instagram.com/v1/tags/'.instagram_tag.'/media/recent?max_tag_id=11&min_tag_id=1&access_token='.intagram_token.'&callback=?');

$cek = json_decode($var);

如果
instagram\u tag
是一个变量,您必须在没有更详细错误消息的情况下预先添加美元符号:
instagram\u tag
(以及
intagram\u token
…或者
instagram\u token
?),我猜您已被阻止。api的使用是否有限制?$var=get_curl(');我试过了,但没用@fusion3k@jeroen我可以从instagram中看到JSON。所以我不这么认为,这取决于,它也可能是基于ip的,所以你的计算机和服务器的结果不一定相同。