Links to friends on Facebook
I am trying to get all the friends of the logged in user and then display them. Each "friend" is listed as a hyperlink. However when I hit the hyperlink nothing happens. I am only prompted with a Facebook logo and when I hit that then I am redirected to the profile. Is it even the correct way of doing it? Atleast the code prints the friends name and id correctly.
$friends = $facebook->api('/me/friends');
开发者_如何学编程$friends = $friends['data'];
foreach($friends as $friend) {
echo "<a href='http://www.facebook.com/profile.php?id=".$friend['id']."'>".$friend['name']."</a><br />";
}
And I have this in the index file in the folder of the canvas url.
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<script>top.location.href = "<?php echo $loginUrl ?>"</script>
<?php endif ?>
When I go the the application on Facebook and I am not logged in I am prompt to login, when I do so I am redirected to the url where the app is hosted, but it is not inside the iframe in Facebook.
This is because you can't have an application or tab iFrame containing a page from the Facebook domain. You need to break out of the iFrame to display the friends profile - the easiest way for you would be to specify a target attribute with your links.
foreach($friends as $friend) {
echo "<a target='_top' href='http://www.facebook.com/profile.php?id=".$friend['id']."'>".$friend['name']."</a><br />";
}
To answer the second part of your question, you need to specify a redirect URI with your login:
<?php
$loginUrl = $facebook->getLoginUrl(
array(
'redirect_uri' => 'http://apps.facebok.com/yourapp/'
)
);
?>
精彩评论