facebook这个功能存在吗?

时间:2014-01-21 18:29:49

标签: php facebook facebook-graph-api

我有一个facebook页面

https://www.facebook.com/Best.Brain.Teasers

和我的网站

http://gpuzzles.com

我已阅读下面的ob facebook链接 https://developers.facebook.com/docs/plugins/comments/

“评论”框可让人们使用他们的Facebook个人资料评论您网站上的内容,并在新闻Feed中向他们的朋友显示此活动。它还包含内置的审核工具和特殊的社交相关性排名。

我可以将我的Facebook页面链接到我的网站 即在我的fb页面墙上发布的所有评论都会自动发布在我的网站/博客上。

1 个答案:

答案 0 :(得分:0)

是的,你可以做到。

只需将以下代码粘贴到您需要发布的网站中即可。只需确保您的服务器已启用Curl并编辑代码以适合您的Facebook ID。

<ul>
<?php
//function to retrieve posts from facebook’s server
function loadFB($fbID){
$url="http://graph.facebook.com/".$fbID."/feed?limit=3";
//load and setup CURL
 $c = curl_init($url);
 curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
//get data from facebook and decode JSON
 $page = json_decode(curl_exec($c));
//close the connection
 curl_close($c);
//return the data as an object
 return $page->data;
}

/* Change These Values */
// Your Facebook ID
$fbid = "YOUR_FB_ID";
// How many posts to show?
$fbLimit = 10;
// Your Timezone
date_default_timezone_set("America/Chicago");


/* Dont Change */
// Variable used to count how many we’ve loaded
 $fbCount = 0;
// Call the function and get the posts from facebook
 $myPosts = loadFB($fbid);


//loop through all the posts we got from facebook
foreach($myPosts as $dPost){
//only show posts that are posted by the page admin
if($dPost->from->id==$fbid){
    //get the post date / time and convert to unix time
     $dTime = strtotime($dPost->created_time);
    //format the date / time into something human readable
    //if you want it formatted differently look up the php date function
     $myTime=date("M d Y h:ia",$dTime);
    ?>
    <ul>
        <li><?php echo($dPost->message) . $myTime; ?></li>
    </ul>
    <?php
    //increment counter
     $fbCount++;
    //if we’ve outputted the number set above in fblimit we’re done
     if($fbCount >= $fbLimit) break;
}
}
?>
</ul>
相关问题