Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中解析Facebook JSON时遇到问题_Php_Json - Fatal编程技术网

在PHP中解析Facebook JSON时遇到问题

在PHP中解析Facebook JSON时遇到问题,php,json,Php,Json,我正试图从Facebook页面上调出帖子,但我遇到了一些问题。我在解析Twitter提要的JSON时没有问题,所以我看不出我遇到了什么问题 这是我的代码,还有: <?php $url = "http://www.facebook.com/feeds/page.php?format=json&id=96551536516"; function disguise_curl($url) { $curl = curl_init(

我正试图从Facebook页面上调出帖子,但我遇到了一些问题。我在解析Twitter提要的JSON时没有问题,所以我看不出我遇到了什么问题

这是我的代码,还有

<?php
    $url = "http://www.facebook.com/feeds/page.php?format=json&id=96551536516";             

    function disguise_curl($url) { 
        $curl = curl_init(); 
        $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: ";

        curl_setopt($curl, CURLOPT_URL, $url); 
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla'); 
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header); 
        curl_setopt($curl, CURLOPT_REFERER, ''); 
        curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); 
        curl_setopt($curl, CURLOPT_AUTOREFERER, true); 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($curl, CURLOPT_TIMEOUT, 10); 

        $html = curl_exec($curl); 
        curl_close($curl);

        return $html;
    }

    $response = json_decode(disguise_curl($url));

    foreach($response->entries as $block){
        echo
            "<li class='clearfix'>
                <div class='streamPosterName'>{$block->author}</div>
                <div class='postContent'>{$block->title}</div>
            </li>";
    }
?>
条目作为$block){
回声
“
  • {$block->author} {$block->title}
  • ”; } ?>
    在页面的其他部分解析JSON时,我使用以下方法引用JSON对象:

    <?php
        $url = "http://search.twitter.com/search.json?q=Apple&rpp=50";             
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $curlout = curl_exec($ch);
        curl_close($ch);
        $response = json_decode($curlout, true);
    
        foreach($response["results"] as $block){
            echo
                "<li class='clearfix'>
                    <img src='".$block["profile_image_url"]."' />
                    <div class='streamPosterName'>".$block["from_user_name"]."</div>
                    <div class='streamPosterUsername'>@".$block["from_user"]."</div>
                    <div class='postContent'>".$block["text"]."</div>
                </li>";
        }
    ?>
    
    {$block->author}
    
    默认情况下,json_decode()将json对象表示为PHP stdClass对象。该错误意味着
    $block->author
    是一个对象,但您使用它的方式就像使用字符串一样


    也许可以试试
    $block->author->name

    如果您定义了“不工作”,那么它会很有帮助。这只是意味着$block->author是Object类型而不是String,因此不是Echoableah dang,愚蠢的错误。没有完全读取JSON对象。谢谢
    <div class='streamPosterName'>{$block->author}</div>
    
    <div class='streamPosterName'>{$block->author}</div>