如何在我的Facebook页面上显示最新的最新帖子到我的网站 [英] how to display latest recent posts in my facebook page to my website

查看:169
本文介绍了如何在我的Facebook页面上显示最新的最新帖子到我的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Facebook上有页面,我想从我的饲料/墙壁上显示最新的5个帖子到我的网站。怎么办?我找到这个解决方案..很容易

i have page on Facebook and I want to display latest 5 posts from my feed/wall on a page to my website. How to do this? I found this solution.. it is easy

https://developers.facebook.com/docs/reference/plugins/like-box/

,有人指导我使用 facebook api 自己
最好的方法是什么?

and someone guide me to use facebook api and do it myself what is the best way?

我使用php mysql构建这个网站

I use php mysql to build this site

推荐答案

这是PHP代码。您需要将其放在您的模板中。

Here is the PHP code. You need to place this in your template.

<ul>
<?php
//function to retrieve posts from facebook’s server
function loadFB($fbID){
    $url = "http://graph.facebook.com/".$fbID."/feed?limit=3";
    // Update by MC Vooges 11jun 2014: Access token is now required:
    $url.= '&access_token=YOUR_TOKEN|YOUR_ACCESS_SECRET';// *

    //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 = "190506416472588";
// 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>

必须做两件事来制作这个脚本。

Two things you must do for working out this script.


  1. 确保您的服务器已启用cURL

  1. Make sure your server is cURL enabled

您将在脚本中更改Facebook ID

You will have change the Facebook ID in the script by yours.

*您可以通过以下方式获取访问令牌:

* You can get the access token this way:

$token = 'https://graph.facebook.com/oauth/access_token?client_id='.APP_ID.'&client_secret='.APP_SECRET.'&grant_type=client_credentials';
$token = file_get_contents($token); // returns 'accesstoken=APP_TOKEN|APP_SECRET'

这篇关于如何在我的Facebook页面上显示最新的最新帖子到我的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆