Get comments and posts from facebook by facebook sdk on website

<?php
include “src/facebook.php”;
$facebook =new Facebook(array(
‘appId’=>’your id’,
‘secret’=>’your secret id’,
‘cookie’=>true
));
$session=$facebook->getUser();
$me=null;
if($session)
{
try
{
$me=$facebook->api(‘/me/posts’);

foreach($me[‘data’] as $friends){
echo    $friends[‘message’];
$t=$facebook->api(“/”.$friends[‘id’].”/comments/”,’Get’);
//print_r($t);
foreach($t[‘data’] as $gh)
{
echo $gh[‘message’].$gh[‘user_likes’].”<br>”;
}
}
$user=$facebook->getUser();
$params = array(
‘message’       =>  “Hello fjfjb)”,
1            );
//    $facebook->api(“/100001524721879_604354879625331/comments/”,’POST’,$params);
//print_r($me);
}catch(FacebookApiException $e)
{
echo $e->getMessage();
}
}
if($me)
{
$logoutUrl=$facebook->getLogoutUrl();
echo “<a href=$logoutUrl>Logout</a>”;
}
else
{
$loginUrl=$facebook->getLoginUrl(array(‘scope’ =>’publish_stream’));
echo “<a href=$loginUrl>Login</a>”;
}
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s