使用Facebook PHP SDK - 身份验证日志记录与返回的会话变量完美配合 - 现在尝试获取详细信息以设置外观样式和用户提供所需的项目。
下面是的基本/我响应 <?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>
试图输出一些Feed - 尝试不同的方式没有结果
<?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>
答案 0 :(得分:2)
实际发生的是你正在使数组$result = $facebook->api('/me');
是数组,所以你需要echo print_r($result)
。所以它会回显你接下来需要从这个数组中获取值的全部信息所以做foreach循环并提取你需要的值。它会帮助你
答案 1 :(得分:0)
<?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 -->