2016-04-05 32 views
0

Ben json biçimi ile bir url veri getirmek için bu php kodu yazdım ve o amele gibi görünüyordu ama ben açtığımda uygun access_token ile $ url koymakFacebook'dan JSON formatı nasıl ayrıştırılır?

 <?php 
    session_start(); 
    $con= mysqli_connect("localhost","root","") or die ("could not connect  to mysql"); 
    mysqli_select_db($con,"facebook_data") or die ("no database"); 
    $url = "https://graph.facebook.com/209024949216061/feed?fields=created_time,from,type,message&access_token=XXXXXXXX"; 
    $ch = curl_init($url); 
    curl_setopt($ch,CURLOPT_HEADER, false); 
    $curlResponse = curl_exec($ch); 

    $data = json_decode($curlResponse,TRUE); 
if (is_array($data) || is_object($data)) { 
foreach($data as $row){ 

    $id=$row["id"]; 
    $created_time=$row["created_time"]; 
    $type=$row["type"]; 
    $message=$row["message"]; 
    $user_id=$row["from"]["id"]; 
    $username=$row["from"]["name"]; 

    $sql="INSERT INTO group_feed(id, username, created_time, user_id, type, message) VALUES('$id','$username','$created_time','$user_id', '$type', '$message')"; 
     if(!mysql_query($sql,$con)) 
     { 
    die('Error : '); 
     } 
    } 
    } 

?> 

veritabanında şey alamadım tarayıcımdaki bağlantı bana sorunun nerede olabileceğini JSON formatı DATA gösteriyor? curl()

ilgili daha fazla bilgi için

cevap

0

$url = "http://graph.facebook.com/".$group_id."/feed/?access_token=".$token; $ch = curl_init($url); curl_setopt(CURLOPT_HEADER, false); $curlResponse = curl_exec($ch);

Kontrol http://php.net/manual/en/book.curl.php Sonra $data = json_decode($curlResponse) kullanarak size bukle yanıtı ayrıştırmak gerekiyor. Yinelenebilecek ilişkisel bir dizi alırsınız (foreach, for, while). Sadece SQL sorgularınızı nasıl yazacağınızı biliyorsunuz.

Not: Bu işe yaramazsa, curl_setopt() işlevine bakın.

İlgili konular