如何在网站上显示Facebook个人资料帖子

时间:2012-10-13 19:18:34

标签: php html css facebook-graph-api

使用php代码

    <ul>
 <!--?<span class="hiddenSpellError" pre=""-->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;
 }


 $fbid=" ID OF THE SPECIFIC FACEBOOK PAGE/PROFILE";
 $fbLimit= howeverManyPostsToBeShown;
 $fbCount=0;
 //variable used to count how many loaded

 //calling the function to get posts from facebook
 $myPosts=loadFB($fbid);

 date_default_timezone_set("Europe/Dublin");

 //loop through all fb posts 
 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 human readable using php date
 $myTime=date("D, d M Y h:ia",$dTime);
 ?>
<ul>
    <li><!--?<span class="hiddenSpellError" pre=""-->php echo($dPost->message);?>
<!--?php echo $myTime;?--></li>
</ul>
 <!--?<span class="hiddenSpellError" pre=""-->php
 //increment counter
 $fbCount++;
 //loop condition break
 if($fbCount >= $fbLimit) break;
 }
 }
 ?>
 </ul>

phpCurl可以从页面或个人资料中显示Facebook墙上的帖子。然而,这可能听起来是一个愚蠢的问题;但是我如何实际回应帖子的内容,处理相关图像的srcs,并给帖子一些相关的格式(例如,给帖子标题提供与其他内容不同的相关CSS)?此外,尝试通过浏览器手动访问页面的帖子扩展名似乎返回错误,例如

`{
   "error": {
      "message": "An access token is required to request this resource.",
      "type": "OAuthException",
      "code": 104
   }
}`

虽然facebook提供a page on the subject乍一看似乎很有用,但它的javascript似乎只是处理记录集分页。

0 个答案:

没有答案