2013-10-08 98 views
1

我試圖獲得來自Facebook數據導入電子表格和我使用的內容,但在代碼中,我有一些問題:PHP Facebook的JSON轉換工具到csv

PHP的警告:無效在/opt/lampp/htdocs/xampp/tratajson.php爲的foreach()提供在線27

這裏的說法是我的代碼:

<?php 
    $arquivo = fopen('/filepath.csv','w'); 
    $request_url ="/filepath.json"; 
    $requests = file_get_contents($request_url); 
    $fb_response = json_decode($requests); 

    foreach ($fb_response->feed->data as $item) 
    { 
    $mensagem=trim($item->message);  
    $mensagem = str_replace(array("\r\n", "\r", "\n","(",")","chr(13)","\t", "\0", "\x0B"), "", $mensagem); 

    $quempostou=$item->from->name; 
    $data=$item->created_time; 

    $ncomentarios=0; 
    $nlikes=0; 
    foreach ($item->comments as $comentarios) 
    { 
     $ncomentarios++; 
     foreach ($comentarios as $comentario) 
     { 
     echo "Quem comentou:"; 
     echo $comentario->from->name; 
     $comentou=$comentario->from->name; 

     echo " Curtir:"; 
     echo $comentario->like_count; 
     $curtidas=$comentario->likecount; 
     $nlikes=$nlikes+$curtidas; 

     echo " Data:"; 
     $datacomentario = $comentario->created_time; 
     echo $datacomentario; 

     echo " Comentario:"; 
     $comentario=$comentario->message; 
        $comentario = str_replace(array("\r\n", "\r", "\n","(",")"), "", $comentario); 
     echo $comentario; 

     $grava="COMENTARIO:".";".$comentario.";".$comentou.";".$datacomentario.";".$curtidas."\n"; 

     fwrite($arquivo,$grava); 

     echo "<br>";  
     } 
    } 

    echo "Quem postou: $quempostou <br>"; 
    echo "Mensagem: $mensagem <br>"; 
    echo "Data: $data <br>"; 
    echo "Comentarios: $ncomentarios <br>"; 
    echo "Likes na thread: $nlikes <br>"; 
    echo "<br><br>"; 

    $grava="POST:".";".$mensagem.";".$quempostou.";".$data.";".$ncomentarios.";".$nlikes."\n\n"; 
    fwrite($arquivo,$grava); 
    } 
    fclose($arquivo); 
?> 

在$ request_url請求的文件具有所有制結構e在頁面Feed的FB Graph API資源管理器中返回的JSON文件的返回值:

有人可以幫助我嗎?

+0

你能後的樣品JSON? –

+0

你可以在這裏看到@AmalMurali: https://developers.facebook.com/tools/explorer?method=GET&path=stackoverflowpage%3Ffields%3Dfeed.limit(1) – lnasci

回答

0

試圖改變這種$fb_response = json_decode($requests);這個$fb_response = json_decode($requests,true);

+0

這種變化我得到以下結果: -PHP注意:嘗試在第10行獲取/opt/lampp/htdocs/xampp/tratajson.php中的非對象屬性-PHP注意:嘗試在/ opt/lampp/htdocs/xampp/tratajson中獲取非對象的屬性.php on line 10 -PHP警告:在第10行 – lnasci

+0

的/opt/lampp/htdocs/xampp/tratajson.php中爲foreach()提供了無效參數,並且在我獲取行之前不會返回電子表格中的任何行但是,像「列表」和「評論」中的列表和計數錯誤等一些錯誤, – lnasci