PHP 函数获取 Facebook 状态?
我正在寻找一个好的、简单的 PHP 函数来获取最新的 Facebook 状态更新。 有人知道其中一个吗?
谢谢!
编辑:我在下面添加了一个半解决方案。
或者是否有人知道读取 RSS 提要并吐出最近状态更新的好方法?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
快速检查 PEAR 发现 Services_Facebook
A quick check on PEAR found Services_Facebook
这是一个不完整的答案,但这是我到目前为止得到的:
首先: 在 FB 上添加开发人员应用程序。 然后创建一个新的应用程序。 随便你怎么称呼它。
第二:下载 PHP 客户端。 转储它位于您的网站主机上的某个位置,即 /facebook/
第三:复制以下初学者代码以开始进入 php 文件:
其他信息:
添加了应用程序。 或者你给
应用程序offline_access
权限并拥有
添加了一个应用程序。
在以下网址中:
http://www.facebook.com/authorize .php?api_key=YOUR_API_KEY&v=1.0&ext_perm=offline_access
程序调用 fql 查询或
users_getInfo,我的页面停止
执行php? 我正在猜测
通话数量有限
对于新的应用程序? 我从来没有
做过任何 FB 开发,所以我
对它完全陌生。 也许使
拨打电话并保存您最近的状态
(或最近的状态)在您的
拥有自己的数据库以防止过度调用
API?
我希望这可以帮助某人入门!
编辑:似乎FB不会让你访问某人的状态,即使offline_access打开,除非你是那个人或他们的朋友(取决于他们的隐私设置)。
不过,我最终还是设法在新的配置文件版本中找到了 RSS 提要: http ://www.new.facebook.com/minifeed.php?filter=11
This is an incomplete answer, but this is what I've gotten so far:
First: add the developer application on FB. Then create a new application. Call it whatever you want.
Second: Download the PHP client. Dump it somewhere on your webhost, i.e. /facebook/
Third: Copy the following beginner code to get yourself started into a php file:
Other info:
application added. OR you give the
application offline_access
permissions and have the
aapplication added.
in the following url:
http://www.facebook.com/authorize.php?api_key=YOUR_API_KEY&v=1.0&ext_perm=offline_access
program calls the fql query or
users_getInfo, my page stops
executing the php? I'm guessing
there are a limited amount of calls
for new applications? I've never
done any FB development so I'm
completely new to it. Maybe make
the call and save your recent status
(or most recent statuses) in your
own DB to prevent excessive calls to
the API?
I hope this helps someone get started!
EDIT: It seems that FB won't let you access someones status, even if the offline_access is on, unless you are that person or their friend (depending on their privacy settings).
I did however, finally manage to find the RSS feed in the new profile version: 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!)
3)现在尝试找出它正在使用的 access_token。 access_token 保存在 fbs_appId cookie 中。 使用浏览器或使用
$_COOKIE['fbs_appId']
找到它。 查找access_token=...
。4) 现在您有了一个(希望)永不过期的 access_token,您可以使用以下代码:
5) 消息部分应位于:
$response['data'][0]['message']
我不知道访问令牌的有效期是多长时间。 脸书说:
I have found a way to fetch your latest facebook status. This is how you do it:
1) Create a facebook app, and copy your application secret and application id.
2) Grant the app read_stream and offline_access to your profile. (http://developers.facebook.com/docs/authentication/permissions) To fetch your latest status the app needs an access_token. With offline_access granted the access_token should "never" expire. The easiest way to do this is to click the button generated by this code: (be sure to fill in 'your app id' and set cookie to true!)
3) Now try to find out what access_token it is using. The access_token is saved in the fbs_appId cookie. Locate it using your browser or using
$_COOKIE['fbs_appId']
. Look foraccess_token=...
.4) Now that you have a (hopefully) never expiring access_token you can use the following code:
5) The message part should be located:
$response['data'][0]['message']
I don't know HOW long the access token is valid. Facebook says:
如果您只想获取最新状态,这是一个非常简单的功能。 它不依赖于 Facebook SDK 或任何东西。 您只需要 CURL 和 JSON 支持。
获取的简单 PHP 函数脸书状态
Here is a REALLY simple function if you just want to get the latest status. It doesn't depend on the Facebook SDK or anything. You just need CURL and JSON support.
Simple PHP function to get facebook status
我似乎从来没有与 PEAR 相处过,但如果你的运气比我好,那么 PEAR 解决方案似乎是长期的最佳途径。
另一个想法是探索 Facebook Developer API 库,看看它是否可以为您提供任何帮助寻找。
最后,曾经有一种获取 RSS 提要的方法...但我似乎找不到任何不再有效的说明,但如果您感兴趣,您可以浏览 Facebook 帮助。 我的最终看起来像这样:
http://www.new.facebook.com/feeds/status.php?id=[idnumber]&viewer=[viewer]&key=[key]&格式=rss20
I never seem to get along with PEAR, but if you have better luck than I, then the PEAR solution seems the best route long term.
Another idea is to explore the Facebook Developer API library and see if that might give you anything you are looking for.
Lastly, there used to be a way to get an RSS feed... but I can't seem to find any instructions that work anymore, but you might poke around Facebook help if that interests you. Mine ends up looking something like this:
http://www.new.facebook.com/feeds/status.php?id=[idnumber]&viewer=[viewer]&key=[key]&format=rss20
我使用 Jens 的帖子检索有效的 access_token 使其正常工作。 然后,我使用以下代码从 xml 文件中提取状态消息和发布时间(您可以更改 $limit 以显示更多或更少的状态消息,或使用表单来更改它)。
请务必输入您的 Facebook ID 和从您创建的应用程序获得的访问令牌(请参阅 Jens 的帖子)。 您可以在此处检查此脚本的输出。
玩得开心!
I got it working using Jens' post to retrieve a valid access_token. Then, I extracted the status messages and the time of posting from the xml file using the following code (you can change $limit to display more or less status messages, or use a form to change it).
Be sure to put in your Facebook ID and the access token you got from the app you created (see Jens' post). You can check the output of this script here.
Have fun!
在过去的几天里,我尝试了很多教程,但没有一个起作用。 我认为这可能是由于 facebook 改变了他们的 api 要求。 这是我发现目前唯一有效的:
http://www.deanblog.co.uk/article/13/adding-a-facebook-status-feed-to-your-website-with-php
I have tried loads of tutorials over the last few days and none of them have worked. I think it may be due to facebook changing their api requirements. This is the only one I found that works at the moment:
http://www.deanblog.co.uk/article/13/adding-a-facebook-status-feed-to-your-website-with-php
只需使用 PHPforFB 框架 (www.phpforfb.com/en/) 即可获得最快的方式。
代码如下所示:
Just use PHPforFB framework (www.phpforfb.com/en/) for the fastest way.
The code looks like this:
由于我无法使用 API 路由,因此我使用了以下位置的 RSS: http://www.new.facebook.com/minifeed.php?filter=11
并使用了以下 PHP 函数,称为 StatusPress,经过我自己的一些修改,用于解析我的 Facebook 状态的 RSS 提要。 效果很好!
Since I couldn't use the API route, I went with the RSS found at: http://www.new.facebook.com/minifeed.php?filter=11
And used the following PHP function, called StatusPress, with some of my own modifications, to parse the RSS feed for my Facebook status. Works great!