我在寻找一个很好的,简单的PHP功能得到我的Facebook状态的更新。任何人都知道的一个吗?

谢谢!

编辑: 我已经加入的一半--解决方案如下。

或者如果有人知道一个很好的方式来解读RSS,吐出了最近状态更新?

有帮助吗?

解决方案 9

由于我无法使用 API 路由,因此我使用了以下位置的 RSS: http://www.new.facebook.com/minifeed.php?filter=11

并使用了以下 PHP 函数, 称为 StatusPress, ,经过我自己的一些修改,解析我的 Facebook 状态的 RSS 提要。效果很好!

其他提示

一个快速检查 发现 Services_Facebook

这是一个不完整的答案,但这是我到目前为止得到的:

第一的: 在FB上添加开发者应用程序. 。然后创建一个新的应用程序。随便你怎么称呼它。

第二: 下载 PHP 客户端。 将其转储到您的虚拟主机上的某个位置,即/Facebook/

第三:复制以下初学者代码以开始使用 php 文件:

 <?php
 require_once('facebook/php/facebook.php');
 $facebook = new Facebook("YOUR_API_KEY","YOUR_SECRET_KEY");
 $result = $facebook->api_client->fql_query("SELECT status FROM user WHERE uid = YOURIDNUMBER");
 // OR --- they both get the same data
 $result = $facebook->api_client->users_getInfo(YOURIDNUMBER,'status');
 print_r($result);
 echo "<pre>Debug:" . print_r($facebook,true) . "</pre>"; // debug info
 ?>

其他信息:

我希望这可以帮助某人入门!

编辑: FB 似乎不会让你访问某人的状态,即使离线访问已打开,除非你是那个人或他们的朋友(取决于他们的隐私设置)。

不过,我最终还是设法在新的配置文件版本中找到了 RSS 提要: http://www.new.facebook.com/minifeed.php?filter=11

我已经找到一种方法来获取你的最新的Facebook状态。这是你如何做到这一点:

1)创建一个Facebook应用,并复制你的应用程序的秘密和应用程序ID

2)给予该应用read_stream和offline_access到配置文件。 ( http://developers.facebook.com/docs/authentication/permissions )向抓取您的最新状态的应用程序需要的access_token。随着offline_access授予应的access_token“从来没有”过期。要做到这一点,最简单的方法是单击该代码生成的按钮:(!一定要填写“您的应用程序ID”和设置cookie的为true)

<fb:login-button perms="read_stream,offline_access"></fb:login-button>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true});</script>

3)现在试图找出它的access_token使用。该是的access_token保存在fbs_appId饼干。使用浏览器或使用$_COOKIE['fbs_appId']找到它。寻找access_token=...

4)现在,你有一个(希望)从不到期的access_token可以使用以下代码:

$access_token='xxxxxxxxxxxxxxxxxxxx';
$appId='123456789132456789';
$appSecret='xxxxxxxxxxxxxxxxxxxx';
$profileId='123456789';

//http://github.com/facebook/php-sdk/blob/master/src/facebook.php
require 'facebook.php';

$facebook = new Facebook(array('appId' => $appId,'secret' => $appSecret));
$response = $facebook->api('/'.$profileId.'/feed?limit=1&access_token='.$access_token);

5)的消息部分应该位于:$response['data'][0]['message']

我不知道过了多久访问令牌是有效的。 Facebook表示:

  

使应用程序在任何时间上代表用户执行授权的请求。默认情况下,大多数访问令牌很短的时间后过期,以确保当正在积极使用的应用程序的应用不仅使代表用户的请求。此权限,使我们的OAuth端点寿命长返回的访问令牌。

下面是一个非常简单的功能,如果你只是想获得最新的状态。它不依赖于Facebook的SDK或任何东西。你只需要卷曲和JSON支持。

简单的PHP函数来获取的Facebook状态

我似乎从来没有与PEAR相处,但如果你有更好的运气比我,那么PEAR的解决方案似乎是最好的途径长远。

另一个想法是探索 Facebook的开发API 库,看看有没有可能给你任何你所期待的。

最后,曾经有一种方式来获得一个RSS feed ...但我似乎无法找到工作了指令,但是如果你感兴趣,你可能会围绕Facebook的帮助捅。矿最终看起来是这样的:

http://www.new.facebook.com/feeds/status.php?id=[idnumber]&viewer=[viewer]&key=[key]&format=rss20

我得到它的工作延用后取回一个有效的access_token。然后,我所提取的状态信息,并使用下面的代码从XML文件发布的时间(可以更改$限制以显示更多或更少的状态消息,或使用窗体来改变它)。

请务必将您的Facebook ID和访问令牌,你所创建的应用程序了(见的延帖子)。您可以检查此脚本的输出这里

玩得开心!

<?php
if(isset($_POST['limit'])) {
    $limit = $_POST['limit'];
}
else {
    $limit = 3; // number of status messages to display
}
$f = fopen ("https://api.facebook.com/method/status.get?uid=YOUR_FACEBOOK_ID&limit=".$limit."&access_token=YOUR_ACCESS_TOKEN", "r");

while ($line= htmlentities(fgets($f))) {
    if ($line===FALSE) print ("FALSE\n");
    else
    {
        $content = $content." ".$line;
    }
}
fclose ($f);

$message = explode("&lt;message&gt;", $content); // search for the <message> tag
$message_cnt = count($message);
$msg_index = 0;

$time = explode("&lt;time&gt;", $content); // search for the <time> tag

for($i=1; $i<$message_cnt; $i++)
{
    $tmp = explode("&lt;/message&gt", $message[$i]);
    $msg[$msg_index] = $tmp[0]; // status message

    $tmp2 = explode("&lt;/time&gt", $time[$i]);
    $t[$msg_index++] = $tmp2[0]; // time of posting
}

for($i=0; $i<$msg_index; $i++)
{
     echo("<span class=\"status\">".preg_replace('!\015\012|\015|\012!','<br>',$msg[$i])."</span><br>\n
           <span class=\"date\">on ".date("d.m.Y", $t[$i])." at ".date("H:i",$t[$i])."</span><br><br>\n");

}
?>

我已经试过教程的负荷在过去的几天,他们都没有工作。我想这可能是由于Facebook的改变他们的API的需求。这是唯一一个我发现,在目前的工作:

http://www.deanblog.co.uk/article/13/adding-a-facebook-status-feed-to-your-website-with-php

只要使用PHPforFB框架( www.phpforfb.com/en/ )为最快的方法。

的代码看起来是这样的:

require_once('phpforfb_framework.php');

$structInit = array('app_id' => APP_ID,'app_name' => APP_NAME,'sec_key' => APP_SECKEY);

$FacebookAPP = new PHPforFB($structInit);

if($FacebookAPP->lastErrorCode>0){
    //Creation failed => Display error message and exit
    echo "PHPforFB Error: ".$FacebookAPP->lastErrorCode." -> ".$FacebookAPP->lastError;
}else{
    //PHPforFB framework established

    if($FacebookAPP->userLoggedIn === TRUE){

        //If the user is logged in at Facebook:
        //Here you can determine if the user has at least once before
        //granted basic permissions to your application.
        if($FacebookAPP->userAuthenticated === FALSE){

            //The user has not yet granted permissions
            //**your code here**
        }else{
            //The user has already granted permissions, therefore his Facebook ID
            //is known to us. It is always available in $FacebookAPP->userID:

            $userID = $FacebookAPP->userID;
            //**your code here**
        }
    }
}
<?php
// see http://github.com/facebook/php-sdk/blob/master/facebook.php
require './facebook.php';
// Create our Application instance.
// see http://www.youtube.com/watch?v=jYqx-RtmkeU for how to get these numbers
$facebook = new Facebook(array('appId' => 'XXX','secret' => 'XXX'));
// This call will always work since we are fetching public data.
// this could be /username or /username/friends etc...
// see developer api for FQL for examples
$status = $facebook->api('/haanmc/feed?limit=1');
?>
<p><?php print $status['data'][0]['message']; ?></p>
<p>Likes: <?php print $status['data'][0]['likes']; ?> | Comments: <?php print count($status['data'][0]['comments']['data']); ?></p>
<textarea style="width: 95%; height: 600px;"><?php print_r($status); ?></textarea>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top