Coyote Red
Coyote Red

Reputation: 33

Facebook PHP SDK Extracting the Feed from the FQL - from php to html

Using Facebook PHP SDK - Authentication logging working perfectly with session variables returning - now trying to get the details out to style the look and the items needed for users feed.

below is the basic /me response which works

 <?php $result = $facebook->api('/me');
$first_name = $result['first_name'];
$last_name = $result['last_name']; ?>
 <p>  <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">  <?php    echo " ".$first_name ." ". $last_name ?> You are now logged In </p>

trying to output some of the feed - trying different ways no result

  <?php $loginLink = $facebook->getLoginUrl(array('scope' => 'email','manage_notifications','user_likes','read_stream','publish_actions','publish_stream','read_friendlists','user_online_presence','friends_online_presence','friends_activities')); ?>

  <?php $resfeed = $facebook->api('/me?fields=feed');  ?>

  <pre><?php print_r($resfeed -> id -> feed -> data[0] -> id); ?></pre> 

  <img src="<?php echo ($result -> id -> feed -> data[2] -> picture) ?>" />
 <img src="https://graph.facebook.com/<?php echo $result; ?>/picture">

  <pre><?php print_r($resfeed); ?></pre> 

Upvotes: 1

Views: 224

Answers (2)

Coyote Red
Coyote Red

Reputation: 33

<?php $loginLink = $facebook->getLoginUrl(array('scope' =>'email','manage_notifications','user_likes','read_stream','publish_actions','publish_stream','read_friendlists','user_online_presence','friends_online_presence','friends_activities')); ?>

<?php $resfeed = $facebook->api('/me?fields=feed');  ?>

<pre> <?php var_dump($resfeed); ?> </pre> 
<pre><?php print_r($resfeed); ?></pre> 

The Facebook feed comes out as an array anyway but below you can encode and decode it to json if you wish to use it that way - I used the facebook array                    

<!--  ======  Encode and Decode JSON  ==================  -->                  

<pre><?php  
$encoded = json_encode($resfeed); 
$decoded = json_encode($encoded, true); 
print_r($decoded); ?> </pre>   


The basic getting to an item:
<?php echo $resfeed['feed']['data']['0']['picture'] ?>
<?php   echo  $resfeed['feed']['data']['0']['link']?> 
<?php   echo  $resfeed['feed']['data']['0']['message']?>


PHP and HTML:


<!--  ----- Feed role out ------- -->
<div class="feed"> 

<?php 
$number = count($resfeed['feed']['data']);
for ($i = 0; $i < $number; $i++)
{ 
echo '<div class="feeds">';

echo '<div class="feedbox">';
echo '<div class="feedboxtop">';   
echo '<img src="https://graph.facebook.com/'.$user.'/picture" width="50px" height"50px" class="circular" style="float:left;" >'; 
echo '<a href="'.$resfeed["feed"]["data"][$i]["link"].'"  >'.$resfeed["feed"]["data"][$i]["link"].'</a> '; 
echo '</div>';
echo '<div class="feedboxright">';

echo '<div class="feedboxleft">';
// echo $resfeed["feed"]["data"][$i]["picture"] ;
$image  = $resfeed["feed"]["data"][$i]["picture"];
echo '<img src="'.$image.'"  style="float:left;margin: 0px 0px 0px 0px" />';

echo '</div>';

echo '<div class="innerbox">';
echo '<a href="'.$resfeed["feed"]["data"][$i]["link"].'"  >'.$resfeed["feed"]["data"][$i]["link"].'</a> '; 
echo'<p>';
echo  $resfeed["feed"]["data"][$i]["message"]; 
echo'</p>';
echo '</div>';
echo '</div>';

echo '<div class="descriptbox"> ';  
echo'<p>';
echo  $resfeed["feed"]["data"][$i]["name"] ; 
echo '</p>';
echo'<p>'; 
echo  $resfeed["feed"]["data"][$i]["description"];
echo'</p>';  

echo '</div>';

echo '<div class="postend" >Posted by '. $first_name ." ". $last_name ; echo'  </div>';
echo '</div>'; // <!-- End of Feedbox class-->

echo '</div>'; // <!-- End of Feeds class -->  

}
?>

</div>  <!-- End Feed class -->   

Upvotes: 0

Aitazaz Khan
Aitazaz Khan

Reputation: 1605

What actually is happening is that you are making array $result = $facebook->api('/me'); is array so you need to echo print_r($result).so it will echo out the whole information about you next you need to fetch the values from this array so do foreach loop and extract the values you need.hope it will help you

Upvotes: 2

Related Questions