Jump to content

Recommended Posts

i keep getting error messages when running this code below but it looks exactly the same as the tutorial i copied it from, i was wondering if someone could take a look and see if the can find my bug

 

Kind Regards

 

$facebook_pade_id = 'id';
$access_token = 'token';
$number_of_posts = 5;
$json_content = file_get_contents('http://graph.facebook.com/'.$facebook_page_id.'/feed?access_token='.$access_token);
$raw_data = json_decode($json_content);
$i=0;
foreach($raw_data->data as $feed) {
$feed_id = explode("_", $feed->id);
if (!empty($feed->message)) {
$i++;
if($i<($number_of_posts+1)) {
?>
<div class="fb_update">
<?php if (!empty($feed->likes->count)) { ?>
<div class="fb_likes">
<?php echo $feed->likes->count; ?>
</div>
<?php } ?>
<?php if (!empty($feed->created_time)) {?>
<div class="fb_date">
<?php echo date('F j, Y', strtotime($feed->created_time));?>
</div>
<?php } ?>
<div class="fb_message">
<?php echo $feed->message; ?>
</div>
</div>
<?php }?>
<?php }?>

Link to comment
https://forums.phpfreaks.com/topic/272732-keep-getting-error-message/
Share on other sites

There are to many if's ;)

You are missing to close a foreach loop.

 

Take a look at that,

 

<?php
$facebook_pade_id = 'id';
$access_token = 'token';
$number_of_posts = 5;
$json_content = file_get_contents('http://graph.facebook.com/'.$facebook_page_id.'/feed?access_token='.$access_token);
$raw_data = json_decode($json_content);
$i=0;
foreach($raw_data->data as $feed):
$feed_id = explode("_", $feed->id);
if (!empty($feed->message)):
$i++;
if($i<($number_of_posts+1)): ?>
<div class="fb_update">
<?php if (!empty($feed->likes->count)) { ?>
<div class="fb_likes"><?php echo $feed->likes->count; ?></div>
<?php } ?>
<?php if (!empty($feed->created_time)) {?>
<div class="fb_date"><?php echo date('F j, Y', strtotime($feed->created_time));?></div>
<?php } ?>
<div class="fb_message"><?php echo $feed->message; ?></div>
</div>
<?php
endif; // end the second if statement
endif; // end the first if statement
endforeach; // end the foreach loop

@jazzman1, I'm going to guess that the problems you found were due to copy/pasting the code, since the OP started other threads for a problem with the string he is building for the file_get_contents statement.

 

Closing this thread since the next thread contains replies earlier than yours.

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.