How can I pull only the messages from a pages Facebook wall using PHP?
I'm trying to pull the content 开发者_如何学Gofrom the following Facebook page: https://graph.facebook.com/100000123344690/feed
I'm already pulling the data successfully using the following:
$ch = curl_init('https://graph.facebook.com/100000123344690/feed');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
$wall = json_decode($response);
var_dump($wall->data);
Now, i'm confused on how I loop over the $wall object and output the message param. Can someone show me a simple loop outputting the message param?
This works:
foreach($wall->data as $post){
echo $post->message;
}
what you're pulling from facebook is json formatted data. you have to convert it to an array in order to loop through it.
You have to pass true to json_decode
to decode it to a multidmensional array, try:
$wall = json_decode($response, true); print_r($wall);
精彩评论