facebook 好友列表分页与 foreach 吗?

发布于 2025-01-06 14:45:24 字数 547 浏览 1 评论 0原文

我正在检索 Facebook 好友列表,但它检索了大约十亿张照片(夸张)。我想知道如何在 foreach 循环中添加分页?另外,我的 PHP 编码是检索好友列表的最佳方法吗?

$user_friends = $facebook->api("/me/friends");

     foreach ($user_friends as $friends) {
      foreach ($friends as $friend) {
         // do something with the friend, but you only have id and name
         $id = $friend['id'];
         $name = $friend['name'];
          echo "<img src='https://graph.facebook.com/".$id."/picture' title='".$name."'>";
         echo $name;

      }

我需要某种 jquery 来进行分页吗?谢谢!

I'm retrieving facebook friendlist, but it retrieves like a billion photos (exaggerated). I was wondering how can I add pagination within a foreach loop? Also, would my PHP coding be the best way to retrieve the friendslist?

$user_friends = $facebook->api("/me/friends");

     foreach ($user_friends as $friends) {
      foreach ($friends as $friend) {
         // do something with the friend, but you only have id and name
         $id = $friend['id'];
         $name = $friend['name'];
          echo "<img src='https://graph.facebook.com/".$id."/picture' title='".$name."'>";
         echo $name;

      }

Would I need some kind of jquery to do the pagination? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聚集的泪 2025-01-13 14:45:24

您可以在 FQL 查询中使用 ORDER BY 和 LIMIT 关键字来实现,这样您只能获取照片的子集。

类似于(伪代码)

$lastid = 0;
do 
{
 $photos = fql("SELECT id from photos where id > $lastid ORDER BY id LIMIT 100")
 foreach $photo in $photos
 {
  ... do stuff ...
  $lastid = $photo->id;
 }
} while ($photos.count > 0)

基本上,您将查询限制为 100 个照片块,并通过排序 ID 来跟踪您所在的位置。

You can use the ORDER BY and the LIMIT keywords in an FQL query to make it so you only get a subset of the photos.

Something like (pseudocode)

$lastid = 0;
do 
{
 $photos = fql("SELECT id from photos where id > $lastid ORDER BY id LIMIT 100")
 foreach $photo in $photos
 {
  ... do stuff ...
  $lastid = $photo->id;
 }
} while ($photos.count > 0)

Basically you are limiting your query to 100 photo chunks and keeping track of where you are by ordering the IDs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文