我正在寻找一个好的,简单的PHP函数来获得我最新的Facebook状态更新。任何人都知道吗?PHP函数获取Facebook状态?
谢谢!
编辑:我添加下面半的解决方案。
或者如果有谁知道RSS feed中的阅读和吐出最近状态更新的好方法?
我正在寻找一个好的,简单的PHP函数来获得我最新的Facebook状态更新。任何人都知道吗?PHP函数获取Facebook状态?
谢谢!
编辑:我添加下面半的解决方案。
或者如果有谁知道RSS feed中的阅读和吐出最近状态更新的好方法?
因为我无法使用API的路线,我用RSS就在这里找到:http://www.new.facebook.com/minifeed.php?filter=11
而且使用了下面的PHP函数called StatusPress,以及我自己的一些修改,来解析我的Facebook状态的RSS feed。很棒!
上PEAR快速检查发现Services_Facebook
我似乎从来没有与PEAR相处,但如果你有更好的运气比我,那么PEAR的解决方案似乎是最好的途径长远。
另一个想法是探索Facebook Developer API库,看看是否有可能给你什么你正在寻找。
最后,曾经有一种方式来获得一个RSS feed ...但我似乎无法找到工作了指令,但是如果你感兴趣,你可能会围绕Facebook的帮助捅。矿最终看起来是这样的:
http://www.new.facebook.com/feeds/status.php?id=[idnumber]&viewer=[viewer]&key=[key]&format=rss20
这是一个不完整的答案,但是这是我到目前为止得到:
第一:add the developer application on FB。然后创建一个新应用程序。随心所欲地调用它。
二:Download the PHP client.转储它的地方,在你的虚拟主机提供商,即/ 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
?>
其他信息:
我希望这可以帮助别人开始!
编辑:即使offline_access处于打开状态,除非您是该人或他们的朋友(取决于他们的隐私设置),FB似乎不会让您访问某人的状态。
,但我却终于设法找到了新的配置文件版本的RSS提要:http://www.new.facebook.com/minifeed.php?filter=11
您应该在某处看到某些东西。当你的php.ini文件中有display_errors = off时,空白输出通常是一个致命错误的标志,转到apache error_log。 FB客户端很好地运行PHP5,并通常在发生错误时抛出相当有意义和详细的异常。 – Ian 2008-12-21 09:21:46
我最终重置了我的SECRET密钥并解决了问题。 但是,我的fql查询不会给出任何结果,除非我包括:$ fb_user = $ facebook-> require_login();. offline_access权限似乎没有正常工作,或者我正在做这个错误。 – 2008-12-21 09:37:29
<?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>
我找到了一种获取您最新的Facebook状态的方法。这是你怎么做的:
1)Create a facebook app,并复制你的应用程序的秘密和应用程序ID。
2)将应用程序read_stream和offline_access授予您的配置文件。 (http://developers.facebook.com/docs/authentication/permissions)要获取您的最新状态,应用程序需要一个access_token。通过授予offline_access,access_token应该“永不”过期。要做到这一点,最简单的方法是单击该代码生成的按钮:(请务必填写“您的应用程序ID”和设置cookie来真的!)
<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中。找到它使用您的浏览器或使用$_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端点返回的访问令牌长久存在。
我知道它使用Jens的帖子来检索有效的access_token。然后,我使用以下代码从xml文件中提取状态消息和发布时间(可以更改$ limit以显示更多或更少的状态消息,或使用表单来更改它)。
请务必在您的Facebook ID和您创建的应用程序中获取访问令牌(请参阅Jens' post)。你可以检查这个脚本的输出here。
玩得开心!
<?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("<message>", $content); // search for the <message> tag
$message_cnt = count($message);
$msg_index = 0;
$time = explode("<time>", $content); // search for the <time> tag
for($i=1; $i<$message_cnt; $i++)
{
$tmp = explode("</message>", $message[$i]);
$msg[$msg_index] = $tmp[0]; // status message
$tmp2 = explode("</time>", $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 SDK或任何东西。你只需要CURL和JSON支持。
我已经试过教程的负荷在过去的几天,他们都没有工作。我认为这可能是由于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**
}
}
}
有趣的问题。我也想要那个答案! – Skuta 2008-12-20 22:17:04
可悲的是,几乎所有下面描述的这些方法都过时了:/ – Petrogad 2011-02-21 21:58:47