You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Facebook PHP SDK获取他人发布到我主页的帖子及发布者信息?

Facebook API: 统计好友在你主页的发帖次数

Great question—this is a common pain point with the modern Facebook Graph API, but there is a way to pull off what you're trying to do for your tie strength script. Let's break it down step by step:

Key Background & Fix

First, let's clarify the endpoints:

  • /me/posts only returns posts you've created yourself—this is why you're not seeing others' content here.
  • /me/feed includes all content that appears on your timeline, including posts friends have made directly to your profile, shares, and more.

The issue you're hitting (missing publisher IDs/names) is almost certainly because you're not explicitly requesting the from field in your API call. The Graph API no longer returns all fields by default; you have to specify exactly what data you want.

How to Get the Publisher Data

When you call /me/feed, add the from field (with nested id and name parameters) to your request. Here's an example of the API call format:

GET /me/feed?fields=id,from{id,name},message,created_time

This will return a from object for every post in your feed, which includes the unique ID and full name of the person who created the post.

Filter & Count Posts

Once you have this data, you can:

  • Filter out any posts where from.id matches your own user ID (these are posts you created yourself)
  • Group the remaining posts by from.id (to avoid name collisions) and count how many times each friend appears—this gives you their post count on your profile.

Critical Permissions Note

To access this data, your access token needs the user_posts permission. For personal use (e.g., analyzing your own profile), you can generate a token with this permission in the Facebook Developer Tools' Graph API Explorer. Keep in mind that for public apps, this permission requires strict app review from Facebook, so it's only feasible for personal projects right now.

Pagination Consideration

If you have a lot of timeline content, the API will return results in pages. You'll need to use the after parameter from the paging object in each response to fetch subsequent pages until there are no more results left.


内容的提问来源于stack exchange,提问作者Garry Welding

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:46:53